Hi guys,
I am having problems with a simple program I wrote, here's the source code:
//seventh
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
class Maths
{
public:
void enterInstructions( int instructions )
{
cout <<"I want to do a: \nAddition\nSubtraction\nType your choice here: "<< instructions << endl;
}
void conditions(int instructions)
{
int result;
int Addition;
int Subtraction;
if ( instructions == Addition )
cout << "Enter the right number: 9+3= ";
cin >> result;
if ( result == 12 )
cout << "Well done, you're a star!";
if ( result != 12 )
cout << "Sorry, wrong answer!";
if ( result < 12 )
cout << "Sorry, wrong answer!";
if ( result > 12 )
cout << "Sorry, wrong answer!";
if ( instructions == Subtraction )
cout << "Enter the right number: 9-3= ";
cin >> result;
if ( result == 6 )
cout << "Well done, you're a star!";
if ( result != 6 )
cout << "Sorry, wrong answer!";
if ( result < 6 )
cout << "Sorry, wrong answer!";
if ( result > 6 )
cout << "Sorry, wrong answer!";
}
};
int main()
{
int myInstructions;
Maths operations;
cout << "What do you want to do?\n";
cin >> myInstructions;
operations.enterInstructions( myInstructions );
operations.conditions( myInstructions );
return 0;
}
The program doesn't execute properly. When I launch the first thing that I see on the screen is the "What do you want to do?" message and then I have to input a character or a number in order to have the next message "I want to do a :" to come up. The thing is that when I type something - in this case the letter d - what I get is the following:
What do you want to do?
d
I want to do a:
Addition
Subtraction
Type your choice here: -858993460
Enter the right number: 9+3= Sorry, wrong answer!Sorry, wrong answer!Enter the r
ight number: 9-3= Sorry, wrong answer!Sorry, wrong answer!Press any key to conti
nue
I am not sure what I have done wrong, I looked at the code again and again, but I am not sure what I can do...
thanks