- Joined
- Oct 7, 2014
- Messages
- 2,208
Hello guys, I'm at lost with my work right now. I don't know why the last part doesn't work in the Y/N to continue. The Y doesn't run the program again.
Code:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
float num1,num2;
char operation,cont,redo;
cout<<"This program will allow you to calculate two numbers."<<endl;
do
{
P1: cout<<" Please enter two numbers";
cout<<" 1st number:";
cin>>num1;
cout<<" 2nd number:" ;
cin>>num2;
cout<<endl;
cout<<" Please enter an operation which you like to use (+, -, *, /, %)";
cin>>operation ;
cout<<endl<<endl;
if (cin.fail())
{
cin.clear();
cout<< "Input is not a number, please try again."<<endl;
cin>>redo;
cout<<endl;
}
P2: switch (operation)
{
case'+':
cout<<"The addition of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1+num2<<endl;
break;
case'-':
cout<<"The substraction of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1-num2<<endl;
break;
case'*':
cout<<"The multiplication of two numbers ("<<num1<<","<<num2<<"):";
cout<<num1*num2<<endl;
break;
case'/':
cout<<"The division of two numbers ("<<num1<<","<<num2<<"):";
if(num2==0)
{
cout<<"not valid"<<endl;
}
cout<<(num1/num2)<<endl;
break;
case'%':
cout<<"The modulus of two numbers ("<<num1<<","<<num2<<"):";
cout<<fmod(num1,num2)<<endl;
break;
default:
cout<<"Input is not a valid operation, please try again."<<endl;
cin>>operation;
goto P2;
}
P3: cout<<"enter Y/N to continue:";
cin>>cont;
switch (cont)
{
case 'Y':
cin>>redo;
goto P1;
case 'N':
break;
default:
cout<<"Input is not a valid value, please try again."<<endl;
cin>>cont;
goto P3;
}
}
while(redo=='Y');
system("pause");
return 0;
}