Just a few questons:
1. Is 999 supposed to exit data entry, or -999?
The programs attempts to compare with 999, but instructions say -999.
2. I would avoid two scanf commands by removing the first one, and interchanging the two line inside the while-loop.
3. The while-loop is badly formatted.
It should start with
while(num!=999){ // != means not equal
scanf...
printf(...
}
Don't forget the braces to "embrace" the loop.
Did your teacher teach cin and cout commands? scanf and printf are C commands, but they do work inside of C++ programs.
Finally, it must be noted that there is no error checking. Any user error will cause the program to halt without warning. But that's normal for a first course in C++.
will this work for a source code that receive and total collection of payroll amounts entered at the terminal until 999 is reached.
#include <stdio.h>
#include <stdlib.h>
main()
{
int num = 0;
printf("Enter number (-999 to quit:");
scanf("%d" ,&num);
while num = 999);
printf("Enter another number (-999 to quit:");
scanf("%d" ,&num);
return 0;
}
1 answer