I've been wondering, if it's possible to check the return value in this function:
1 2 3 4 5 6 7 8 9 10 11 12 13
double Test()
{
double num = 0;
if(!(cin>>num)){
cout << "Error: Bad input type, must be a number... As I haven't been able to make the error message work\
\n close down the console yourself...";
num = Test;
cin.clear();
cin.clear();
}
return 1;
}
So basically what this does is give an error message if the input isn't a number.
In main you'd get something like this:
1 2 3 4 5 6 7 8
cout << "Enter number 1: ";
num1 = Test();
cout<<"\nEnter number 2: ";
num2 = Test();
// the function for additions/ substractions
result = num1 + num2;
cout<<num1<<" + "<<num2<<" = "<<result<<"\n";
What currently happens if the Test() returns 1, is that the program doesn't crash, but it just displays the error message, and then result of 1+1=2 (so it runs as if nothing happend..)
So my question is, can I make the program check if Test() has returned 1 and then make it skip the output of the result?
if(num2 == 1)
{
//num2 is 1 code here
cout << "Num2 is 1!";
}
else
{
//num2 is not 1 code here
cout << "Num2 is not 1 :<";
}
Read about control structures here http://cplusplus.com/doc/tutorial/control/
Theyre very very very important and you will most likely always use them in everything you write
You used an if statement in your Test() function but i guess that was just copy paste work =P