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 the large sustained error signal that eventually cause the controller output to drive to its limit

1 Answers   TCS,


what is exceptions?

5 Answers   HCL, Wipro,


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


difference between c/c++ programing language? what is necessesity of c++ when existing c programing language?

2 Answers   TCS,


I can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not, but it only tells thet the word is not a palindrome. And I can't fix it.

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  


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  


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  


Find the error (2.5*2=5) (a) X=y=z=0.5,2.0-5.75 (b) s=15;

3 Answers  


main() { char c; for(c='A';c<='Z';c++) getch(); }

9 Answers  


what is the error in the following code: main() { int i=400,j; j=(i*i)/i; }

4 Answers  


Write down the difference between c. Loop and goto statement d. (!0) and (!1) e. (1= =! 1) and (1!=1) f. NULL and !NULL

0 Answers  


Categories