Questions:

1. Write a program that reads two integer numbers and calculates the result according to the option chosen from the following menu:

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Description of the options:

- Option 1: compare both numbers and print out a message with the larger one.

- Option 2: check if the first number is multiple of the second and vice versa.

- Option 3: ends the program. One statement will be in this case which is exit(0).

- If the user enters a wrong option, an error message should be displayed.

Hint: Use switch statements.

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 1

20 is larger than 10

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 2

20 is a multiple of 10

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 3

Thank you!!and Goodbye..

_____________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 5

Sorry!!.. You have chosen a wrong option.. Goodbye!!

______________________________________

my solve ::::

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

int x,y,choice;

while(1)

{

system("cls");

cout<<"Please enter two integers: \n "

<<"\tenter the first intiger : ";

cin>>x;

cout<< "\tenter the second intiger : ";

cin>>y;

cout<< "\n\n(1)-Define large."

<< "\n(2)-One multiple of other."

<< "\n(3)-Exit." ;

cout<<"\nEnter your choise: ";

cin>>choice;

switch (choice)

{

case 1: if(x != y)

if (x>y)

cout<<x<<" is larger than "<<y<<endl;

else

cout<<y<<" is larger than "<<x<<endl;

else cout<<y<<" == " <<x;

getch();

break;

case 2:

if (x%y == 0)

cout<<x<<" is a multiple of "<<y<<endl;

else

if (y%x == 0)

cout<<y<<" is a multiple of "<<x<<endl;

else cout<<x<<" is not a multiple of " <<y<<" and vice versa";

getch();

break;

case 3:

cout<<"Thank you !! and Goodbye.."<<endl;

exit(o);

break;

default:

cout<<"sorry!!..you have to chose a number from 1 to 3 "<<endl; getch();

}

}

return 0;

};

but when i do run tell me i have some erroe

can you help me plz ^_^

1. Write a program that reads two integer numbers and calculates the result according to the option chosen from the following menu:

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Description of the options:

- Option 1: compare both numbers and print out a message with the larger one.

- Option 2: check if the first number is multiple of the second and vice versa.

- Option 3: ends the program. One statement will be in this case which is exit(0).

- If the user enters a wrong option, an error message should be displayed.

Hint: Use switch statements.

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 1

20 is larger than 10

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 2

20 is a multiple of 10

______________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 3

Thank you!!and Goodbye..

_____________________________________

Please enter two integers: 10 20

***************************

1- Define large.

2- One multiple of other.

3- Exit.

***************************

Enter your choice: 5

Sorry!!.. You have chosen a wrong option.. Goodbye!!

______________________________________

my solve ::::

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

int x,y,choice;

while(1)

{

system("cls");

cout<<"Please enter two integers: \n "

<<"\tenter the first intiger : ";

cin>>x;

cout<< "\tenter the second intiger : ";

cin>>y;

cout<< "\n\n(1)-Define large."

<< "\n(2)-One multiple of other."

<< "\n(3)-Exit." ;

cout<<"\nEnter your choise: ";

cin>>choice;

switch (choice)

{

case 1: if(x != y)

if (x>y)

cout<<x<<" is larger than "<<y<<endl;

else

cout<<y<<" is larger than "<<x<<endl;

else cout<<y<<" == " <<x;

getch();

break;

case 2:

if (x%y == 0)

cout<<x<<" is a multiple of "<<y<<endl;

else

if (y%x == 0)

cout<<y<<" is a multiple of "<<x<<endl;

else cout<<x<<" is not a multiple of " <<y<<" and vice versa";

getch();

break;

case 3:

cout<<"Thank you !! and Goodbye.."<<endl;

exit(o);

break;

default:

cout<<"sorry!!..you have to chose a number from 1 to 3 "<<endl; getch();

}

}

return 0;

};

but when i do run tell me i have some erroe

can you help me plz ^_^

other solve but agine i have error

#include <iostream>

using namespace std;

int main()

{

int x,y,choice;

cout<<"Please enter two integers: ";

cin>>x>>y;

cout<<"Enter your choise: ";

cin>>choice;

switch (choice)

{

case 1:

if (x>y)

cout<<x<<" is larger than "<<y<<endl;

else

cout<<y<<" is larger than "<<x<<endl;

break;

case 2:

if (x== 2*y)

cout<<x<<" is a multiple of "<<y<<endl;

else

if (y== 2*x)

cout<<y<<" is a multiple of "<<x<<endl;

break;

case 3:

cout<<"Thank you !! and Goodbye.."<<endl;

exit(o);

break;

default:

cout<<"sorry!!..you have chosen a wrong option.. Goodbye!!"<<endl;

}

return 0;

}

#include <iostream>

using namespace std;

int main()

{

int x,y,choice;

cout<<"Please enter two integers: ";

cin>>x>>y;

cout<<"Enter your choise: ";

cin>>choice;

switch (choice)

{

case 1:

if (x>y)

cout<<x<<" is larger than "<<y<<endl;

else

cout<<y<<" is larger than "<<x<<endl;

break;

case 2:

if (x== 2*y)

cout<<x<<" is a multiple of "<<y<<endl;

else

if (y== 2*x)

cout<<y<<" is a multiple of "<<x<<endl;

break;

case 3:

cout<<"Thank you !! and Goodbye.."<<endl;

exit(o);

break;

default:

cout<<"sorry!!..you have chosen a wrong option.. Goodbye!!"<<endl;

}

return 0;

}

Topic archived. No new replies allowed.