|
From: Mary S. <ms...@in...> - 2001-07-12 03:45:48
|
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
|