Write a program that reads 2 numbers and print their + - * / as following:
My code:
#include<iostream>
using namespace std;
#include<exception>
void menu();
int add(int a, int b);
int sub(int a, int b);
int mult(int a, int b);
int Div(int a, int b);
int avg(int a, int b);
bool IsZero(int a, int b);
void main()
{
int choice;
do
{
menu();
int a, b;
//int choice;
cout << "\t\t\tEnter your choice: ";
cin >> choice;
cout << "\t\t\t--------------------------" << endl;
switch (choice)
{
case 1:
cout << "\t\t\tEnter Number #1: ";
cin >> a;
cout << "\t\t\tEnter Number #2: ";
cin >> b;
cout << "\t\t\tResult: " << add(a, b) << endl;
cout << "\t\t\t--------------------------" << endl;
break;
case 2:
cout << "\t\t\tEnter Number #1: ";
cin >> a;
cout << "\t\t\tEnter Number #2: ";
cin >> b;
cout << "\t\t\tResult: " << sub(a, b) << endl;
cout << "\t\t\t--------------------------" << endl;
break;
case 3:
cout << "\t\t\tEnter Number #1: ";
cin >> a;
cout << "\t\t\tEnter Number #2: ";
cin >> b;
cout << "\t\t\tResult: " << mult(a, b) << endl;
cout << "\t\t\t--------------------------" << endl;
break;
case 4:
cout << "\t\t\tEnter Number #1: ";
cin >> a;
cout << "\t\t\tEnter Number #2: ";
cin >> b;
cout << "\t\t\tResult: " << Div(a, b) << endl;
cout << "\t\t\t--------------------------" << endl;
break;
case 5:
cout << "\t\t\tEnter Number #1: ";
cin >> a;
cout << "\t\t\tEnter Number #2: ";
cin >> b;
cout << "\t\t\tResult: " << avg(a, b) << endl;
cout << "\t\t\t--------------------------" << endl;
break;
case 6:
cout << "\t\t\tSee you later!\n";
cout << "\t\t\t--------------------------" << endl;
break;
default:
cout << "\t\t\tPlease, choose from menu.";
cout << "\t\t\t--------------------------" << endl;
break;
}
cout << "\n\n";
} while (choice!=6);
}
//menu
void menu()
{
cout << "\t\t\t -------------------------" << endl;
cout << "\t\t\t| Program Math operations |" << endl;
cout << "\t\t\t -------------------------" << endl;
cout << "\t\t\t1- Add numbers.\n";
cout << "\t\t\t2- Sub numbers.\n";
cout << "\t\t\t3- Mult numbers.\n";
cout << "\t\t\t4- Div numbers.\n";
cout << "\t\t\t5- Avg numbers.\n";
cout << "\t\t\t6-End program.\n";
cout << "\t\t\t--------------------------" << endl;
}
//Add
int add(int a, int b)
{
return a + b;
}
//sub
int sub(int a, int b)
{
return a - b;
}
//mult
int mult(int a, int b)
{
return a * b;
}
//div
int Div(int a, int b)
{
return a / b;
}
//Avg
int avg(int a, int b)
{
int c;
c = a + b;
return c / 2;
}
No comments:
Post a Comment