Am trying to Write a program that will read two numbers and an integer code from the screen. The value of the
integer code should be 1, 2, 3 or 4. If the value of the code is 1, compute the sum of the two numbers.
If the code is 2, compute the difference (first minus second). If the code is 3, compute the product of
the two numbers. If the code is 4, and the second number is not zero, compute the quotient (first
divided by second). If the code is not equal to 1, 2, 3 or 4, display an error message. The program is
then to display the two numbers, the integer code and the computed result to the screen. can anyone help me???
I mean no offense, but this is kinda a question that would belong in the beginner's forum. :/
Now. I assume you haven't written anything. Here are a few snippets I can give you to help out. Note that these are only templates, and you will need to do still some programming.
int a, b, c;
std::cin >> a >> b >> c;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
switch (c)
{
case 1:
//Code here.
break;
case 2:
//Code here.
break;
case 3:
//Code here.
break;
case 4:
//Code here.
break;
default:
std::cout<<"FAIL.\n";
break;
}
int main ()
{
system("cls");
system("TITLE Problem 1");
system("color f6");
int num1, num2, code;
cout<<"\n";
cout<<"\t\tPLEASE ENTER THE TWO NUMBERS YOU WANT TO BE CALCULATED";
cout<<"\n";
cout<<"ENTER NUM1:";
cin>>num1;
cout<<"\n";
cout<<"ENTER NUM2:";
cin>>num2;
cout<<endl<<"HOW DO YOU WANT TO CALCULATE YOUR NUMBERS";
cout<<"\n";
cout<<"\n";
cout<<"1 SUM";
cout<<"\n";
cout<<"2 Difference";
cout<<"\n";
cout<<"3 Product";
cout<<"\n";
cout<<"4 Quotient";
cout<<"\n";
cout<<"\n";
cout<<"\t\tCHOICE between 1 and 4:";
cin>>code;
cout<<"\n";
if(code==1){
int sum=num1 + num2;
cout<<"THE SUM IS: "<<sum;
cout<<"\n";
cout<<"\nANY KEY TO RETURN TO MAIN:";
getch();
main();
}else if(code==2){
int difference = num1 - num2;
cout<<"THE DIFFERENCE IS: "<<difference;
cout<<"\n";
cout<<"\nANY KEY TO RETURN TO MAIN:";
getch();
main();
}else if(code==3){
int prod = num1 * num2;
cout<<"THE PRODUCT IS: "<<prod;
cout<<"\n";
cout<<"\nANY KEY TO RETURN TO MAIN:";
getch();
main();
}else if(code==4){
if(num2==0) {
cout<<"THE QUOTIENT CANT BE FOUND AS THE DIVIDER IS 0";
cout<<"\n";