Hello everyone i`m new to this forum but not new to programming i was bored so i start making a program to enter your bill then program ask u to if u want to + or - the tva on the bill then after all this it ask u to enter the value of the tva.
the program works perfect but there is a small problem if u enter a wrong value above 100 then i have to start it all over . here the program.
#include <iostream>
using namespace std;
int main()
{
int bill;
float TVA,value;
char o; //operator (+ or -)
cout<<"___________________________________________________"<<endl;
cout<<"Please enter your bill |"<<endl;
cout<<"___________________________________________________|"<<endl;
cin>>bill;
system("cls");
cout<<"would you like to '+' or '-' the tva"<<endl;
cout<<"write (+) for raise tva or (-) for discount"<<endl;
cin>>o;
if(o !='+' && o !='-') //if u didn`t enter + or - then i dunno how to make it return to the same if
{
cout<<"wrong operator please write '+' or '-'"<<endl;
return main();
}
else
{
system("cls");
cout<<"___________________________________________________"<<endl;
cout<<"please enter the value of the tva |"<<endl;
cout<<"___________________________________________________|"<<endl;
cin>>value;
if(value < 0 || value > 100) //if u didn`t enter less than 0 or greater than 100 then i dunno how to make it return to the same if
{
cout<<"wrong value please enter between 0 and 100"<<endl;
return main();
}
else
{
system("cls");
if(o == '+')
{
TVA=bill*(value/100);
cout<<"Bill Value:"<<bill<<endl;
cout<<"bill value + TVA= "<<bill+TVA<<" with "<<value<<"%"<<endl;
}
else if(o == '-')
{
TVA=bill*(value/100);
cout<<"Bill Value(L.L):"<<bill<<endl;
cout<<"bill value - TVA= "<<bill-TVA<<" with "<<value<<"%"<<endl;
}
}
}
system("pause");
return 0;
}
so now the problem in those lines
1 2 3 4 5
if(o !='+' && o !='-') //if u didn`t enter + or - then i dunno how to make it return to the same if
{
cout<<"wrong operator please write '+' or '-'"<<endl;
return main();
}
and
1 2 3 4 5
if(value < 0 || value > 100) //if u didn`t enter less than 0 or greater than 100 then i dunno how to make it return to the same if
{
cout<<"wrong value please enter between 0 and 100"<<endl;
return main();
}
i don`t want to start it over by ordering the program to return to main, so is there any other way to make it return only to if statement?