Ok I will mention as much as faster I can my problem since I don't have enough length character as my program is to big.. So I will post one part of the program (one function and it will be the same for the others ) The program works fine but I want when the user add characters (etx:acbd/?<) at addition number I want to print an error message and ask from the user to enter the correct input.. For example::
********
Addition
********
Enter two numbers to addition:
f + f
(the program output::)
Error input. Please used only number.
Enter two number to addition:
2 + 3
(the program NOW output::)
The total sum of 2 + 3 = 5
The total of sum is now 5
The total sum of f + f = 0
The total of sum is now 5
Why the compiler skip the else statement of error???
I am really confused please if you have any ideas please let me know as soon as possible... My code is below:::
void addition() //function for the addition operation...
{
string num1,num2;
double x,y; //variables of the void
cout << "**********"<<endl;
cout << "*Addition*"<<endl;
cout << "**********"<<endl; // welcome screen
cout << "Enter 2 numbers to calculate: "<<endl;
cin >> num1>>num2;
x = atof(num1.c_str());
y = atof(num2.c_str()); //change string to double
if (num1=="0") //check the string if is number
{
sum+= atof(num1.c_str()); //add the converted string into sum
}
elseif (num2=="0") //check the second input
{
sum+=atof(num2.c_str()); //add the converted string into sum
}
elseif ((x == 0) || (y == 0)) //check if the input is string and prints an error message
{
cout <<"Error input.Please add only numbers"<<endl;
cout <<endl;
sum = 0.0; //reset the sum if the input is string or char
addition(); //call the fnc again for the inputs
}
x = atof(num1.c_str());
y = atof(num2.c_str()); //confirm the convention of x , y numbers
total = x + y; // the program makes the calculation of the to numbers
sum += total; // save the value and keep
cout <<"The total sum of "<<num1<<" + "<<num2<<" = "<<total<<endl; //prints out the equation
cout << "The total of sum is now "<<sum<<endl;
cout <<endl;
} // end brackets of addition function....