Leo, Mikey, Donnie, and Raph are having a pizza-eating contest. Each day, each o
ID: 3745476 • Letter: L
Question
Leo, Mikey, Donnie, and Raph are having a pizza-eating contest. Each day, each of them eats a certain number of slices of pizza. Unfortunately, good pizza is expensive, so they would like to keep track of how many total slices they eat each day.
Your Task You should write a very small C++ program that does these things:
First, your program should read four integers from standard input (that is, from cin). The numbers will all be zero or positive. (These numbers represent the number of pizza slices eaten by Leo, Mikey, Donnie, and Raph respectively on a certain day.)
If at least one of the four numbers is greater than zero, then add all four numbers together, and print the total to standard output (that is, to cout) on a line by itself. (This represents the total amount of pizza eaten by all four of them that day.) Then go back to the start and read the next line of input.
When the program reaches a line with all four input numbers equal to 0, this is the signal that the pizza-eating contest is over. Your program should terminate.
Here’s an example run, with the input shown in italics:
5 6 2 0
13
3 2 77 22
104
0 0 1 0
1
6589 3219 84721 3984
98513
0 0 0 0
Explanation / Answer
here the program is:
#include<iostream.h>
int main()
{
int p1,p2,p3,p4,total;
do{
cin>>p1>>p2>>p3>>p4; //input to the program
total = p1+p2+p3+p4;
cout<<total<<endl;
}while(p1>0||p2>0||p3>0||p4>0); // check for atleast one value should be non zero
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.