0

C program

how do i write a program, the user want a mathmatical operation the what to perform if the user type for Example "m" indicating multiplication then program ask the user to enter a number num1 and num2. after the user entered the number the sum sould be displayed with an appriate display message.

30th Mar 2019, 11:09 AM
ayibatonye wariebi
2 Respostas
0
One way would be to specify the character "m" as the multiplication setting. For instance, here's a piece of the program, using the string class supported in c++ 11: #include <string> //include this to specify you will be working with the string class #include <cmath> //include this to support math functions, like multiplying,etc using namespace std; int main() { string input=" "; // this specifies the letter, in this case"m" as input int num1=0,num2=0; cout<<"Enter m for multplication"<<endl; cin>>input; if (input=="m") //if the user typed in m, it should then prompt for two numbers to multiply { cout<<"Enter the two numbers to multiply"<<endl; cin>>num1; cin>>num2; cout<<"Their products are"<<num1*num2<<endl; } }
31st Mar 2019, 5:10 PM
Justin
Justin - avatar
0
thanks
31st Mar 2019, 5:47 PM
ayibatonye wariebi