Written this calculator but wanted to let you see if it is good or not. I am using "Microsoft Visual C++ 2010"
My question is how do I use the looping statement so the user can choose to start over or exit? Can some one give me an example?
// Test.cpp : Defines the entry point for the console application.
/**********************************************************/
/* The Calculator */
/* by: Mesmaroth */
/**********************************************************/
#include "stdafx.h"
#include <iostream>
int main() // main function
{
int user_answer;
std:: cout << "Please choose a problem.\n";
std:: cout << "Press 1 for addition.\n";
std:: cout << "Press 2 for subtraction.\n";
std:: cout << "Press 3 for multiplication.\n";
std:: cout << "press 4 for division.\n";
std:: cin >> user_answer;
if (user_answer>=5) // if the user inputs a number from 5 and above they will get this error
{
std:: cout << "Oops! You picked a wrong number\n";
std:: cout << "Please choose the correct number.\n";
}
switch (user_answer)
{
case 1: (user_answer==1); // addition
{
int user_number1;
int user_number2;
std:: cout << "Please choose the first number.\n";
std:: cin >> user_number1;
std:: cout << "Please choose the second number.\n";
std:: cin >> user_number2;
std:: cout << user_number1 << '+' << user_number2 << '=' << user_number1+user_number2 << std:: endl;
break;
}
case 2: (user_answer==2); // subtraction
{
int user_number1;
int user_number2;
std :: cout << "Please choose the first number.\n";
std:: cin >> user_number1;
std:: cout << "Please choose the second number.\n";
std:: cin >> user_number2;
std:: cout << user_number1 << '-' << user_number2 << '=' << user_number1-user_number2 << std:: endl;
break;
}
case 3: (user_answer==3); // multiplication
{
int user_number1;
int user_number2;
std:: cout <<"Please choose the first number.\n";
std:: cin >> user_number1;
std:: cout << "Please choose the second number.\n";
std:: cin >> user_number2;
std:: cout << user_number1<< '*' << user_number2 << '=' << user_number1*user_number2 << std:: endl;
break;
}
case 4: (user_answer==4); //division
{
float user_number1;
float user_number2;
std:: cout << "Please choose the first number.\n";
std:: cin >> user_number1;
std:: cout << "Please choose the second number.\n";
std:: cin >> user_number2;
std:: cout << user_number1 << '/' << user_number2 << '=' << user_number1/user_number2 << std:: endl;
break;
}