hi everyone. im stumped on this C++ code i have to write.
i have to write a code where the user either enters a S for sum, or P for product. if neither s or p is entered, the program is to display "error".
after that the user enters a series of numbers until the they enter 1, which ends the number entering.
next, i need to output either the sum or product (which ever was selected previously) of the numbers entered.
this is what the code should look like when it is run, the bolded letters and numbers are is what the user has to imput.
this is what it looks like when getting the SUM
-----------------------------------------------------------------------
Sum or Product? s
enter numbers (enter 1 to stop): 2 3 4 6 12 1
the sum of your numbers is : 27
------------------------------------------------------------------------
this is what is looks like when getting the PRODUCT
------------------------------------------------------------------------
Sum or Product? P
enter numbers (enter 1 to stop): 2 3 4 6 12 1
the product of your numbers is : 1728
----------------------------------------------------------------
this is what is looks like when you dont enter an s or p
-------------------------------------------------------------
Sum or Product? f
Error
-------------------------------------------------------------------
!!!!PLEASE HELP ME WITH WRITING THE CODE FOR THIS!!!!!!
bool answered = false;
char chosen;
while(answered == false){
std::cout << "Please choose what to do:\n1-Sum [S]\n2-Product[P]" <<std::endl;
std::cin>>chosen;
if(chosen=='S' || chosen=='P'){answered=true;}
}
/*
You really are a lazy ass...
This is the question loop. Need the rest too? \n is New Line.*/