Alright, so I'm using switches and -
Add and Subtract works well with no problem. But it is Multiply and Divide that is making my head scratch.Code:#include <iostream> using namespace std; int x; int a; int b; int e = 100; int f = 50; int g = 10; int h = 10; void Add() { cout <<"\n Added 100 to " << a + b + x<< "\n"; cout << "Your final result is -\n" << e + x + a + b; } void Subtract() { cout <<"\nSubtract 50 from " << x + a + b << "\n"; cout << "Your final result is -\n" << x + a + b - f; } void Multiply() { cout <<"\nMultiplied 10 with " << x + a + b << "\n"; cout << "Your final result is -\n" << x + a + b * g; } void Divide() { cout <<"\nDivided 10 to " << x + a + b << "\n"; cout << "Your final result is -\n" << x + a + b / h; } int main() { cout << "Please input a number: "; cin >> x; cin.ignore(); cout << "\nYou have entered " << x << ". Please hit ENTER to continue"; cin.get(); cout << "\nPlease enter two numbers to be added to " << x << " :"; cin >> a >> b; cin.ignore(); cout << "\nThe total is - " << a + b + x << ". " << "Please hit ENTER to continue"; cin.get(); int c; cout<<"1. Add\n"; cout<<"2. Subtract\n"; cout<<"3. Multiply\n"; cout<<"4. Divide\n"; cin>> c; switch (c) { case 1: Add(); break; case 2: Subtract(); break; case 3: Multiply(); break; case 4: Divide(); break; default: cout<<"Input not recognized. Quitting now\n"; break; cin.get(); } }
If I put 100 into x, a and b and use Multiply to multiply 300 by 10, it doesn't return 3000, it returns 1200...
For Divide, if I put the same number, 100, into x, a and b and use Divide to divide 300 by 10, it doesn't return 30, it returns 210...
Does anyone know how to fix this?



LinkBack URL
About LinkBacks




