My name is Emiljan and i just graduated high school and i am going to school for programming in the fall semester, I want to be a C++ Programmer and i am starting to learn now so i can have some experience before i start college.
Ive been learning C++ for almost two weeks now and so far i have learned enough to make a simple calculator in C++ using the CodeBlocks ide.
What i want to learn next is how to make the program loop so i doesn't exit after you chose to do one problem.
Right now it only does the option you choose once, then exits but i want to make it loop the same function or another function of your choosing, until you tell it to exit.
I need some help to make my program do what i want it to.
- Code: Select all
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
signed long int num1, num2;
signed long int ans;
cout<<" SIMPLE CALCULATOR! " << endl;
cout<< endl;
cout<<"1. Addition " << endl;
cout<<"2. Subtraction " << endl;
cout<<"3. Multiplication " << endl;
cout<<"4. Division " << endl;
cout<<"5. Exit Program " << endl;
cout<< endl;
cout<<"Please chose a number<1-5>: " ;
cin >> ans;
if (ans == 1)
{
cout<< endl;
cout<<"(Simple Addition) " << endl;
cout<<"Please enter first number: " ;
cin >> num1;
cout<<"Please enter second number: " ;
cin >> num2;
cout << endl;
cout <<"The answer is: " << num1 + num2 << endl;
}
if (ans == 2)
{
cout<< endl;
cout<<"(Simple Subtraction) " << endl;
cout<<"Please enter first number: " ;
cin >> num1;
cout<<"Please enter second number: " ;
cin >> num2;
cout << endl;
cout <<"The answer is: " << num1 - num2 << endl;
}
if (ans == 3)
{
cout<< endl;
cout<<"(Simple Multiplication) " << endl;
cout<<"Please enter first number: " ;
cin >> num1;
cout<<"Please enter second number: " ;
cin >> num2;
cout << endl;
cout <<"The answer is: " << num1 * num2 << endl;
}
if (ans == 4)
{
cout<< endl;
cout<<"(Simple Division) " << endl;
cout<<"Please enter first number: " ;
cin >> num1;
cout<<"Please enter second number: " ;
cin >> num2;
cout << endl;
cout <<"The answer is: " << num1 / num2 << endl;
}
if (ans == 5)
{
cout << endl;
cout << endl;
cout<< "Thank You! ";
exit (1);
}
system("pause");
return 0;
}
