Re: [Dev-C++] Basic C question: scanf
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Eric A. <eri...@ho...> - 2001-07-12 17:08:31
|
Or you coul do
//Add the following lines
#include <ctype.h>
#define Done 0;
#define True !done;
While(!done)
then somewhere in the loop ask if they was to continue
printf("Would you like to enter more values? Y/N/x20");
ch=toupper(gets(ch));
If(ch == 'Y') Done = True;
then end the loop.
>----- Original Message -----
>From: "Mary Sipple" <ms...@in...>
>To: <dev...@li...>
>Sent: Thursday, July 12, 2001 4:47 AM
>Subject: [Dev-C++] Basic C question: scanf
>
>
> > I've written a short program using Dev-C++ 4, but it does not execute as
>I
> > would expect. The code is as follows:
> >
> > #include <stdio.h>
> >
> > int main(int argc, char *argv[])
> > {
> > double salary, fed_withhold, state_withhold;
> > double salary_sum = 0, fed_sum = 0, state_sum = 0;
> >
> > printf("Enter salaries: ");
> > while (scanf("%lf", &salary) == 1){
> > fed_withhold = salary * .17;
> > state_withhold = salary * .03;
> > printf("salary: %.2f fed tax: %.2f state tax: %.2f\n",
> > salary, fed_withhold, state_withhold);
> > salary_sum += salary;
> > fed_sum += fed_withhold;
> > state_sum += state_withhold;
> > }
> > printf("\nSalary total: %.2f Fed tax total: %.2f State tax total:
>%.2f\n",
> > salary_sum, fed_sum, state_sum);
> >
> > system("PAUSE");
> > return 0;
> > }
> >
> > When the program is run, the prompt "Enter salaries:" is printed. After
> > that, I enter a series of numbers, then press the Enter key. The printf
>in
> > the loop is executed for each number input, but then the program hangs.
>I
> > have to either interrupt the program (<cntrl>-z worked for this) or type
>in
> > alpha characters and hit Enter. At that point the printf after the while
> > loop is executed.
> >
> > What have I got wrong or what is it that I don't understand?
> >
> > Thanks,
> >
> > Mary
> >
> >
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
>
>_______________________________________________
>Dev-cpp-users mailing list
>Dev...@li...
>http://lists.sourceforge.net/lists/listinfo/dev-cpp-users
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
|