Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

executing programs in Turbo C++ "run" window

hi,
here is the program:

/*file:avrage.c*/
#include

/* calculate the average of three numbers */
void main()
{
int num1, num2, num3;
float avg;

printf("enter 3 integer numbers:");
scanf(" %d %d %d ", &num1, &num2, &num3);


avg = num1+num2+num3;

avg = avg/3;

printf("the average is:%f",avg);

}
dumb question: what to do after i entered the numbers in TC++ "run" window? because pressing the "Enter" button does nothing.






Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : hi,
    : here is the program:
    : [code]
    : /*file:avrage.c*/
    : #include
    : [color=Red]#include[/color]
    :
    : /* calculate the average of three numbers */
    : void main()
    : {
    : int num1, num2, num3;
    : float avg;
    :
    : printf("enter 3 integer numbers:");
    : scanf(" %d %d %d ", &num1, &num2, &num3);
    :
    :
    : avg = num1+num2+num3;
    :
    : avg = avg/3;
    :
    : printf("the average is:%f",avg);
    :
    : [color=Red]getch();[/color]
    : }
    [/code]
    : dumb question: what to do after i entered the numbers in TC++ "run"
    : window? because pressing the "Enter" button does nothing.
    :
    :
    :
    :
    :
    :
    :
  • earlyriser1earlyriser1 Posts: 5Member
    [b]brilliant!!
    thank you very much[/b]

    2 basic questions:

    1)is there any function that will except hitting "Enter", and not an actual character to display the average?

    2)is there a way to [b]clear[/b] the "run" window, and the "user screen" window, without restarting Turbo C++ ?
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : [b]brilliant!!
    : thank you very much[/b]
    :
    : 2 basic questions:
    :
    : 1)is there any function that will except hitting "Enter", and not an
    : actual character to display the average?
    :
    : 2)is there a way to [b]clear[/b] the "run" window, and the "user
    : screen" window, without restarting Turbo C++ ?
    :
    [color=Blue]
    Question #1 I am not sure I understand. Did you mistype 'accept'? What exactly you need to do? Also, the average displayed BEFORE you hitting any keys. Also, you can easily input ENTER instead of any other character - it will work the same way.

    Question #2.

    Simply call function clrscr() and it will clear the screen.
    [/color]
  • earlyriser1earlyriser1 Posts: 5Member
    1# yes sorry - i mistyped 'accept'.
    and for me the average [b]does not[/b] display before i hit any keys. after i insert the numbers i must hit a letter key (doesn't matter which one) and then ENTER - only then will i see the average...

    2# - thanks - it worked :-)

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]Wow! You are correct!
    I just tried this code on my TC 201 and indeed you need
    to enter something before seeing the average value.

    I found the cause, however. ;-)

    The formatting string is " %d %d %d ".
    Notice the blanks on both sides. Simply remove them.
    The formatting string is now "%d %d %d". And the problem is gone!
    It is most likely the bug in Turbo C itself.
    I am not sure the C/C++ standard has anything to say about this behavior, so it is most likely a bug in TC. Well, it was long ago.

    I have added some colors to your program.
    Have fun![/color]
    [code]
    /*file:avrage.c*/

    #include
    #include
    #include

    /* calculate the average of three numbers */
    void main()
    {
    int num1, num2, num3;
    float avg;

    textcolor (WHITE);
    cprintf("
    enter 3 integer numbers: ");
    textcolor (LIGHTGREEN);
    cscanf("%d %d %d", &num1, &num2, &num3);


    avg = num1+num2+num3;

    avg = avg/3;

    textcolor (YELLOW);
    cprintf("
    the average is:%f",avg);

    bioskey (0);
    textcolor (LIGHTGRAY);
    }
    [/code]
    [color=Blue]If you want to know where all those functions come from - simply put cursor on a name of any function or constant, like YELLOW, and press CTRL+F1.[/color]
  • earlyriser1earlyriser1 Posts: 5Member
    Awesome! It worked!
    Nice debugging skills man ;-)

    And the [color=Blue]c[/color][color=Green]o[/color][color=Orange]l[/color][color=yellow]o[/color][color=Red]r[/color][color=purple]s[/color] are much better thank you...

    You've been a great help man. Much much appreciated :-D
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]You can also do graphics programs and it will all work in Win XP DOS box. Here is how to discover functions for it:[/color]
    [code]
    #include
    [/code]
    [color=Blue]Then put a cursor on 'graphics.h' and press CTRL+F1 - it should give the list of functions in that header. Read on![/color]
  • earlyriser1earlyriser1 Posts: 5Member
    Thanks, right on it! :-)
  • nathanpcnathanpc Posts: 9Member
    Please, put the code tags!

    Thanks!
  • didi312didi312 Posts: 1Member

    Cheap Men Gucci Jackets (Www.Edhardy4sale.Com) Wholesale Gucci Men's Jackets (Www.Edhardy4sale.Com) Discount Gucci Jackets For Mens

    Coogi ED Hardy Urban Clothing (Www.Edhardy4sale.Com) Cheap Hip Hop Gucci Clothing Wholesale

    Gucci Womens Sandals (Www.Edhardy4sale.Com)

    Gucci Mens Denim Shorts (Www.Edhardy4sale.Com)

    Gucci Mens Denim Jeans (Www.Edhardy4sale.Com)

    Gucci Belts (Www.Edhardy4sale.Com)

    Gucci Mens Short Sleeve Tee Shirts (Www.Edhardy4sale.Com)

    Gucci Womens Short Sleeve Tees (Www.Edhardy4sale.Com)

    Gucci Women Short Sleeve Polo Shirts (Www.Edhardy4sale.Com)

    Gucci Short Sleeve Polos For Big Men (Www.Edhardy4sale.Com)
Sign In or Register to comment.