63 050
Assignments Done
99,1%
Successfully Done
In July 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions