Answer to Question #14924 in C++ for Darryl kaye Sanga

Question #14924
Write a loop that will read in list of even number (such as 2, 24, 8, 6) and compute the total of the numbers on the list. The list is ended with a sentinel value. Among other things, you must decide what would be a good sentinel value to use.
1
Expert's answer
2012-09-14T10:07:48-0400
#include "stdafx.h"
#include <conio.h>
#include <iostream>

using namespace std;


int main()
{
int number;
int sum=0;
cout<<"Enter number(-1-exit): ";
while (cin >> number) {
if(number%2==0){
cout<<"Enter number(-1-exit): ";
if(number==-1){
break;
}else{
sum += number;
}
}else{
cout<<"Enter even number: ";
}
if(number==-1){
break;
}
}
cout<<"Sum= "<<sum;
cout<<"
Press any key to exit...";
getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS