I need some help with my first program. It compiles just fine... but that is just about it. It is supposed to be a simple calculator but has many problems.
First of all I cant seem to get the program to return to the menu after each calculation. Also it always performs addition first than division...doesnt matter which choice you make.
should I be using boolean variables instead?Code:#include <cstdlib> #include <iostream> #include <cstdio> using namespace std; int nChc; int nValue1; int nValue2; int main(int argc, char *argv[]) { cout << "Welcome to the DOS Calculator!!!\n" << "Please choose from a list of choices:\n" << "1) Addition\n" << "2) Subtraction\n" << "3) Multiplication\n" << "4) Division\n" << "Enter 1-4: "; cin >> nChc; if (nChc = 1) { cout << "Enter two values to be added:\n" << "Value 1: "; cin >> nValue1; cout << "Value 2: "; cin >> nValue2; int sum = nValue1 + nValue2; cout << nValue1 << " + " << nValue2 << " = " << sum << "\n"; } else if (nChc = 2) { cout << "Enter two numbers to be subtracted\n" << "Value 1: "; cin >> nValue1; cout << "Value 2: "; cin >> nValue2; int minus = nValue1 - nValue2; cout << nValue1 << " - " << nValue2 << " = " << minus << "\n"; } else if (nChc = 3) { cout << "Enter two numbers to be multiplied\n" << "Value 1: "; cin >> nValue1; cout << "Value 2: "; cin >> nValue2; int product = nValue1 * nValue2; cout << nValue1 << " * " << nValue2 << " = " << product << "\n"; } else (nChc = 4); { cout << "Enter two numbers to be divided\n" << "Value 1: "; cin >> nValue1; cout << "Value 2: "; cin >> nValue2; float quotient = nValue1 / nValue2; cout << nValue1 << " / " << nValue2 << " = " << quotient << "\n"; } system("PAUSE"); return EXIT_SUCCESS; }



LinkBack URL
About LinkBacks




start it at -1 or anything really. You should also do some error checking to make sure that the choice is within the right range.That was my fault, sorry. Didn't compile my pseudo-code
oops...my bad lol...works just fine now. THANKS