I’d like your help with understanding why this function does not stop when I enter any other number than 1.
int main(void) {
double sum,v;
while (scanf("%lf",&v)==1) {
printf("\t%.2f\n", sum += v);
}
It looks like it’s suppose to stop whenever the input would be different from 1. I believe that it is has to do with the condition, maybe it checks something before what I think it does.
The function
scanfreturns the number of items matched and filled, not the actual value it read.So in your code
scanfwill always return1for a successful read. You should be testingvinstead (but not with==).