christopher, a high school computer whiz kid, has been challenged by his cousin Thea, a math genius, to compute for integer using the four basic arithmetic operations using a computer program. however, thea, wanting his dear cousin to fail, deliberately increased the complexity on how it will be done. from her explanation, integers entered in the console by users should be temporarily stored into a variable and later copied to an array, digit by digit.
she then added that the arithmetic operation, except division, must be done digit by digit in the array, starting from its last element progressing to the first. just like the normal way.
#include <iostream>
using namespace std;
void add(int a1[], int a2[]){
}
void subtract(int a1[], int a2[]){
}
void multiply(int a1[], int a2[]){
}
void divide(int a1[], int a2[]){
}
int main (){
int num1, num2, x;
char again;
do{
cout << "Type 2 integers seperated by space: ";
cin>>num1>>num2;
cout << "[1] Add [2] Subtract [3] Multiply [4] Divide" <<endl;
cout << "Please choose operation: ";
cin>>x;
if (x==1){
add(num1, num2);
}
else if (x==2){
subtract(num1, num2);
}
else if (x==3){
multiply(num1, num2);
}
else if (x==4){
divide(num1, num2);
}
else{
cout << "Error: Input not recognized!" <<endl;
}
cout << "Try Again? [y/n]: ";
cin>>again;
}while (again != 'n');
return 0;
}

New Topic/Question
Reply




MultiQuote





|