Given that two int variables, total and amount, have been
declared, write a loop that reads integers into amount and
adds all the non-negative values into total. The loop
terminates when a value less than 0 is read into amount.
Don't forget to initialize total to 0.


Instructor's notes: This problem requires either a while or
a do-while loop.

Answers were Sorted based on User's Feedback



Given that two int variables, total and amount, have been declared, write a loop that reads integer..

Answer / helen

total=0;
cin>>amount;
while (amount>=0)
{
total=total+amount;
cin>>amount;
}

Is This Answer Correct ?    43 Yes 20 No

Given that two int variables, total and amount, have been declared, write a loop that reads integer..

Answer / cammy pope

total=0;

cin>>amount;
total= total+amount;
cin>>amount;
total= total+amount;
cin>>amount;
total= total+amount;

Is This Answer Correct ?    10 Yes 13 No

Given that two int variables, total and amount, have been declared, write a loop that reads integer..

Answer / abhishek rajput

int total=0, amount;
scanf("%d",&amount);
while(amount>0)
{
total=total+amount;
scanf("%d",&amount);
}
printf("total=%d",total);

Is This Answer Correct ?    1 Yes 5 No

Post New Answer

More C C++ Errors Interview Questions

what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?

1 Answers  


Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.

3 Answers  


Declaration of Cube Guys please help me.. Is this a right way to declare cube.? If i Compile it. It Says: Cube undeclared what should i do? Please help \thanks in advanced #include<stdio.h> #include<math.h> #include<conio.h> main( ) { float x,y; while(x++<10.0) { printf("Enter Number:"); scanf("%d", &x); y = cube(x); printf("%f %f %f \n", x,pow(x,2),y); cube(x); } { float x; float y; y = x*x*x; } getch(); return (y); }

2 Answers  


what is the large sustained error signal that eventually cause the controller output to drive to its limit

1 Answers   TCS,


Write a c-programe that input one number of four digits and find digits sum?

2 Answers  






write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


what is run time error?

7 Answers  


#include<stdio.h> void main() { int i=1; printf("%d%d%d",i++,++i,i); }

19 Answers  


errors are known as?

3 Answers   EX, State Bank Of India SBI,


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  


I am using Qt 5.6 during compilation it stops and gives error about Qmake The process "C:QtQt5.6.35.6.3msvc2015_64inqmake.exe" crashed. Error while building/deploying project untitled1 (kit: Desktop Qt 5.6.3 MSVC2015 64bit) When executing step "qmake"

0 Answers  


what is syntax error?

3 Answers  


Categories