My calculator

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;
}


}
char exit;
std:: cout << "Press 'Q' to quit.\n";
std::cin >> exit;
if (exit == 'q' || exit == 'Q')
{
std:: cout << "Goodbye!\n";
}
while (exit != 'Q' && exit != 'q');
return 0;
}
use do while loop like this

1
2
3
4
5
6
7
8
9
10
int main()
{
char choose='y';
do{

//you program body here


}while(choose=='y');

look this previous question you you will get more Idea
http://www.cplusplus.com/forum/general/52210/
Topic archived. No new replies allowed.