#include<iostream>
#include<cmath>

using namespace std;

int main()
{
float user1;
float user2;
float sum;
char choice;
for (;;)
     do {
    cout<<"Calculator";
    
    

cout << "Enter your first number" << endl;
cin >> user1;
cout << "Enter your function \n";
cout << "+ \n";
cout << "- \n";
cout << "x \n";
cout << "/ \n";
cin >> choice;

case "+": //addition
cout << "Enter your second number" << endl;
cin >> user2;

cout << user1 + user2;
cout << endl << "Sum equals" << sum;
break;

case "-": //subtraction
cout << "Enter your second number" << endl;
cin >> user2;

cout << user1 - user2;
cout << endl << "Sum equals" << sum;
break;

case "x": //multiplication
cout << "Enter your second number" << endl;
cin >> user2;

cout << user1 * user2;
cout << endl << "Sum equals" << sum;
break;

case "/": //division
cout << "Enter your second number" << endl;
cin >> user2;

cout << user1 / user2;
cout << endl << "Sum equals" << sum;
break;

do
{
	cout << "Press 'q' to quit or 'c' to continue: ";
	cin >> choice;
	} while (choice != 'c' && choice != 'q');
} while (choice == 'c');
system("PAUSE");
return 0;


}

Ok, so I think I need a switch somewhere for the cases... but not too sure. I'm trying to make a calculator where there's an option to enter q for quit... not even sure if i have that right. Any help would be great!

Recommended Answers

All 4 Replies

Sintax is as follows

yo need a break and a default case

switch(var int o char)

{

case const1: instruction(s);

break;

case const2:  instruction(s);
break;

case const3:  instruction(s);

break; ………………

default:  instruction(s);

};

im still not too sure where to put that stuff.. im very new to all this

In line 26 you must write "switch (choice) {"

In line 58 "}"

whitout quotation marks

Maybe it might be a good idea to look up switch in your book. Books generally explain these things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.