Menu

[solved]-Code Needs Able Run Way Expected Goodbye Output 0001 Enter~~number ~5 0002 5~sums~~15 00 Q39006751

The code needs to be able to run all the way through. What isexpected is “Goodbye!”.

==================== YOUR OUTPUT=====================                                                                                                              

0001:Enter~a~number:~5                                                                                                                                             

0002:5~sums~to~15                                                                                                                                                  

0003:Enter~a~number:~25                                                                                                                                            

0004:25~sums~to~325                                                                                                                                                

0005:Enter~a~number:~100                                                                                                                                           

0006:100~sums~to~5050                                                                                                                                              

0007:Enter~a~number:~0                                                                                                                                             

0008:0~sums~to~0        

=================== MISMATCH FOUND ON LINE 0008:===================                                                                                                

ACTUAL  :0~sums~to~0                                                                                                                                               

EXPECTED:Goodbye!                                                                                                                                                  

======================================================                                                                                                              

                                                                                                                                                                    

Adjust your program and re-run totest.                                                                                                                             

                                                                                                                                                                    

Test 1 Failed

#include <iostream>
#include <string>
using namespace std;

int sumTo(int number) {
int counter = 1;
int total = 0;
while (counter <= number) {
total = total + counter;
counter = counter +1;
}
return total;
}
int main () {
int answer;
int number = 1;
while (number != 0) {
cout<<“Enter a number: “;
cin>>number;
if (number != 1) {
answer = sumTo(number);
cout<<number <<endl;
cout<<number <<” sums to ” <<answer<<endl;
}
}
return 0;
}

Expert Answer


Answer to The code needs to be able to run all the way through. What is expected is “Goodbye!”. ==================== YOUR OUTPUT =… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *