So what this porgram should do is the following: ask for a number between 50 and 100, if the input is not between the 2, an error message wil show up and it will ask for the numbers again, this part works.
The second part asks for the sign of a wanted mathematical operation, if a wrong character is input an error message shows up and the program asks for the sign again. this part works as well.
The last part should be the easiest but the if else if sytax is giving me problems. This part is supposed to execute either an summation, subtraction,division or multilpication, based on which sign is input but does not at it's current form. No matter which one of the 4 avaliable signs are input the program will only run the first if, so the summation, and nothing else.
Side notes: Firstly the program was originally written with Hungarian expression, i translated those parts when copy pasting the code here, i might have forgotten about a a bit of text here and there. Secondly i am using Visual Studio 2015.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
using namespace std;
int main()
{
int i,num1, num2;
char operation;
do {
cout << "Input 2 numbers between 50 and 100! \n";
cin >> pont1 >> pont2;
if (num1 < 50 || num2 < 50 || num1>100 || num2>100) cout << "Wrong number(s)! \n";
} while (num1 < 50 || num2 < 50 || num1>100 || num2>100);
do {
cout << "Input sign of wanted operation(+,-,*,/) \n";
cin >> operation;
if (operation != '+' && operation != '-' &&operation!= '/' && operation != '*') cout << "Incorrect sign of operation \n";
} while (operation != '+' && operation != '-' && operation != '/' && operation != '*');
if (operation = '+')cout << "The 2 numbers added together: " << (num1 + num2) << endl;
else if (operation = '-')cout << "The first one minus the 2nd: " << (num1 - num2) << endl;
else if (operation = '/')cout << "The first number devided by the 2nd: " << num1 / num2 << endl;
else if (operation = '*')cout << "The 2 numbers multiplied: " << (float)num1*(float)num2 <<endl;
system("pause");
return 0;
|