hey guys first time here

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???
can anyone help me???
That very much depends on what problems you're having.
Last edited on
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;
}


Have fun! :)

-Albatross



Last edited on
i did all of this, but i was having problems with my variables. thanks
@Albatross

I think you used << wrong?
It should be:

std::cin >> a >> b >>c;

Or not?

-Xander
Argh. Right, it's the other way. Thanks for noticing.

Let this be a lesson to anyone who's reading this! Don't post distracted, or you could get in a nasty accident!

-Albatross

EDIT: Xander stole my style of signing posts. <3
Last edited on
Damn, you found out :)

I'll do it more creative from now on.

~Xander
thanks for the push Albatross, i finally get it. but i didnt use the switch i use the a if statement...... it look like this


#include <iostream>
#include <conio.h>
#include <math.h>

using namespace std;


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";

}
else {
float quot = round(num1/num2);
cout<<"THE QUOTIENT IS: "<<quot;
cout<<"\n";

cout<<"\nANY KEY TO RETURN TO MAIN:";
getch();
main();

}
}
else {
cout<<"INCORRECT CHOICE";
cout<<"\n";
cout<<"\nANY KEY TO RETURN TO MAIN:";

getch();
main();
}



getch();
return 0;
}


Topic archived. No new replies allowed.