I'm making a calculator that is Supposed to calculate floating point values, but somethign goes wrong along the way (can't be sure what). It calculates intagers just fine, but when I add a decimal with an extra intager on, something funky happens. It infinitly displays a rounded number. For instance, if I type in "3+1.3", instead of displaying "4.3" once like it should, it will just display "4" line by line infinatly over the time span that I don't hit the X at the top right. Can someone perhaps tell me a solution to this? If it will help, I have the code right here:
Code:
#include <iostream> using namespace std; int main() \\calculator function { cout << "Press '*' to multiply two numbers (ex: 2*2 plus enter key)\n\n"; \\start of instructions cout << "Press '/' to divide two numbers (ex: 2/2 plus enter key)\n\n"; cout << "Press '+' to add to two numbers (ex: 2+2 plus enter key)\n\n"; cout << "Press '-' to subtract a number from another(ex: 2-2 plus enter key)\n\n"; \\end of instructions cout << "Press 'Q' or 'q' to exit\n\n"; char character; while(character != 'Q') { long double value; getline(cin, value, '*' || '/' || '+' || '-'); cin >> character; long double value2; getline(cin, value2) if(character == '*') { cout << value * value2 << endl;} if(character == '/') { cout << value / value2 << endl;} if(character == '+') { cout << value + value2;} if(character == '-') { cout << value - value2;} } return 0; }
Comment