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

A sample program using data structure? what is file handling?

0 Answers   TCS,


who was the present cheif governor of reserve bank of india

6 Answers   State Bank Of India SBI,


how to convert decimal to hexadecimal without using arrays just loops

2 Answers  


void main() { int i=5; printf("%d",i+++++i); }

14 Answers   HCL,


Assume that the int variables i and j have been declared, and that n has been declared and initialized. Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consistings of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be * ** *** You should not output any space characters. Hint: Use a for loop nested inside another for loop.

2 Answers   HCL,


Why are memory errors hard to debug?

1 Answers  


which typw of errors ? & how to solve it ?

0 Answers  


char* f() return "hello:"; void main() {char *str=f(); }

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 meant for variable not found?

3 Answers  


when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;

2 Answers  


How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis

0 Answers  


Categories