0% found this document useful (0 votes)
33 views2 pages

Simple C++ Calculator Program

This C++ program is a simple calculator that allows a user to input two numbers and an operator to perform basic math operations of addition, subtraction, multiplication, and division. It uses a switch statement to evaluate the operator and calculate the answer. The user can then choose to perform another calculation or quit the program.

Uploaded by

Shun Fujinami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views2 pages

Simple C++ Calculator Program

This C++ program is a simple calculator that allows a user to input two numbers and an operator to perform basic math operations of addition, subtraction, multiplication, and division. It uses a switch statement to evaluate the operator and calculate the answer. The user can then choose to perform another calculation or quit the program.

Uploaded by

Shun Fujinami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

//Filename: Calculator.

cpp
//Programmer: Shun Fujinami
//Project #1
//Due Date: 9/24/13
//Program Description: Calculator
//CSCI 123 Fall '13 Instructor: Timothy Mai
//Date Submitted: 9/24/13
#include <iostream>
using namespace std;

int main()
{
double firstNumber, secondNumber, answer;
char oprator, repeat = 'y';
int toggle = 0;
cout << "Welcome to Calculator 6000! \nCalculator 6000! can add, subtract,
multiply, and divide! \n";
do
{
do
{

cout << "Please enter first number, operator, then second number: ";
cin >> firstNumber >> oprator >> secondNumber;
switch (oprator)
{
case'+':
answer = firstNumber + secondNumber;
toggle = 0;
break;
case'-':
answer = firstNumber - secondNumber;
toggle = 0;
break;
case'*':
answer = firstNumber * secondNumber;
toggle = 0;
break;
case'/':
answer = firstNumber / secondNumber;
toggle = 0;
break;
default:
cout << "Invalid operator, please enter +, -, *, or /
\n";
toggle = 1;
}
}while(toggle == 1);
cout << firstNumber << " " << oprator << " " << secondNumber << " = " <<
answer << endl;
do
{
cout << "Would you like to do another? (y/n): ";
cin >> repeat;
if(repeat == 'n' || repeat == 'N' || repeat == 'y' || repeat == 'Y')
break;
else
cout << "Sorry, I do not understand" << endl;
}while(repeat != 'n' || repeat != 'N' || repeat != 'y' || repeat != 'Y');
}while(repeat == 'y' || repeat == 'Y');

cout << "Have a nice day!" << endl;

return 0;
}

You might also like