Hi, I have created a calculator, i would like to make it so that it restarts back to beginning or to make is so it doesn't quit at the end, letting you input more numbers to solve.
#include <iostream>
using namespace std;
int a;
int b;
int choice;
int add;
int sub;
int mult;
int div;
int main(){
cout <<"**Welcome to Jon's Calculator**" <<endl;
cout <<"Choose a number " <<endl;
cin >>a;
cout <<"Choose another number" <<endl;
cin >>b;
cout <<"What do you want to do? \n 1.Add \n 2.Subtract \n 3.Multiply \n 4.Divide" <<endl;
cin >>choice;
if (choice==1){
add=a+b;
cout <<"The sum of the two numbers chosen is: " <<add <<endl;
}
if (choice==2){
cout <<"The diffrence of the two numbers is: " <<a-b <<endl;
cout <<"Or: " <<b-a <<endl;
}
if (choice==3){
cout <<"The value obtained multiplying the two numbers is: " <<a*b <<endl;
}
if (choice==4){
cout <<"The value obtained from dividing the first number by the second number is: " <<a/b;
cout <<"With a remainder of: " <<a%b <<endl;
cout <<"The value obtained from dividing the second number by the first number is: " <<b/a;
cout <<"With a remainder of: " <<b%a <<endl;
}
if (choice>4){
cout <<"Sorry, that is not a command i recognize. " <<endl;
}
if (choice<1){
cout <<"Sorry, that is not a command i recognize. " <<endl;
}
}
#include <iostream>
usingnamespace std;
int main(){
int a, b, choice, add, sub, mult; // declare variables here, global are generally
//bad unless you know what your doing and WHY/WHEN to use them
bool repeat = true;
while(repeat){//this will repeat the program infinitely
cout <<"**Welcome to Jon's Calculator**" <<endl;
cout <<"Choose a number " <<endl;
cin >>a;
cout <<"Choose another number" <<endl;
cin >>b;
cout <<"What do you want to do? \n 1.Add \n 2.Subtract \n 3.Multiply \n 4.Divide" <<endl;
cin >>choice;
if (choice==1){
add=a+b;
cout <<"The sum of the two numbers chosen is: " <<add <<endl;
}
if (choice==2){
cout <<"The diffrence of the two numbers is: " <<a-b <<endl;
cout <<"Or: " <<b-a <<endl;
}
if (choice==3){
cout <<"The value obtained multiplying the two numbers is: " <<a*b <<endl;
}
if (choice==4){
cout <<"The value obtained from dividing the first number by the second number is: " <<a/b;
cout <<"With a remainder of: " <<a%b <<endl;
cout <<"The value obtained from dividing the second number by the first number is: " <<b/a;
cout <<"With a remainder of: " <<b%a <<endl;
}
if (choice>4){
cout <<"Sorry, that is not a command i recognize. " <<endl;
}
if (choice<1){
cout <<"Sorry, that is not a command i recognize. " <<endl;
}
}
return 0; // you forgot this. all functions but void need a return value
}