I am trying to design an algorithm for a simple calculator function. But everytime i enter in a symbol to have it perform an operation it always adds. Also, the while loop never terminates even when i say no.
#include <iostream>
using namespace std;
Code:int main () { // Variable Declarations int num1, num2, num3, num4; char letter, symbol; // Prompt cout << "This Program will add, subtract, multiply, and divide" << "the two numbers you enter." << endl; cout << endl; while (letter = 'y') { cout << "Please enter two numbers: "; cin >> num1 >> num2; cout << endl; cout << "Please input the operation you would like to use: "; cin >> symbol; cout << endl; if (symbol = '+') { num3 = num1 + num2; cout << "The sum is: " << num3 << endl; } else if (symbol = '-') { num3 = num1 - num2; cout << "The difference is: " << num3 << endl; } else if (symbol = '*') { num3 = num1 * num2; cout << "The product is: " << num3 << endl; } else if (symbol = '/') { num3 = num1 / num2; num4 = num1 % num2; cout << "The quiotient is: " << num3 << "The remainder is: " << num4 << endl; } else cout << "Invalid symbol." << endl; cout << "Would you like to run the program again [y/n] "; cin >> letter; cout << endl; } cout << "End of Program" << endl; return 0; }



LinkBack URL
About LinkBacks


