This is a more advanced calculator which gives the user a choice :P
LINK FOR THE SIMPLE CALCULATOR HERE
Source Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int a,b;
cout << "Please choose one of the following: " << endl; cout << "1) + " << endl << "2) - " << endl; cout << "3) * " << endl << "4) / " << endl; cout << "0) Exit " << endl; cout << "Choice: "; cin >> a;
if (a==1)
{
system("cls");
cout << "Please enter the first number: "; cin >> a;
system("cls");
cout << a << " + "; cin >> b;
system("cls");
cout << "a + b = " << a+b; } else if (a==2) { system("cls"); cout << "Please enter the first number: "; cin >> a;
system("cls");
cout << a << " - "; cin >> b;
system("cls");
cout << "a - b = " << a-b; } else if (a==3) { system("cls"); cout << "Please enter the first number: "; cin >> a;
system("cls");
cout << a << " * "; cin >> b;
system("cls");
cout << "a * b = " << a*b; } else if (a==4) { system("cls"); cout << "Please enter the first number: "; cin >> a;
system("cls");
cout << a << " / "; b=0; while (b=0) { cin >> b;
}
system("cls");
cout << "a / b = " << a/b;
}
else {return 0;}
cout << endl;
system("pause");
return 0;
}
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου