NEED ASSISTANCE!!! if statements & loops

!!!!!!!PLEASE HELP!!!!!!!

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!!!!!!
Make some code that prints out

-----------------------------------------------------------------------

Sum or Product?


and then read in something from the keyboard.

Come back when you've done that, or if you struggle to do that, show us the code you write in trying and we shall help.
i know how to get the typed stuff up on the screen, i just dont know how to write a code to imput the s or p and the imput of the numbers
HELP!!!
still need help with the code!!!
What happened when you used cin?
i do not know what to cin, i only know how to get the phrases to output on the screen. i need someone to do the code
1
2
3
4
5
6
7
8
9
10
11
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.*/
Oh, and it's input, iNput.
I know this code may contain weaknesses but I'm sure this will work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
int main()
{
    char process;
    int num,sum,prod;
    cout<< "Sum or Product?\n";
    cin>> process;
    if (process=='s'|| process=='S')
    {
        cout<< "Enter the numbers (1 to stop)\n";
        cin>> num;
        sum=num;
        do
        {
            cin>> num;
            sum=sum+num;
        }
        while (num!=1);
        cout<< "sum = " << sum <<endl;
    }
    else if (process=='p'|| process== 'P')
    {
        cout<< "Enter the numbers (1 to stop)\n";
        cin>> num;
        prod=num;
        do
        {
            cin>> num;
            prod=prod*num;
        }
        while (num!=1);
        cout<< "product = "<<prod<<endl;
    }
    else
    {
        cout<< "Invalid choice.\n";
    }
    return 0;
}

thanks alot!
Topic archived. No new replies allowed.