If statement

If you have an if statement, what do you do to end the program if that statement is true but not if false?

1
2
3
4
cout<<"Enter total minutes parked:"<<endl;
cin>>totalMinutes;
if(totalMinutes==0)
cout<<"You have not entered a valid number"<<endl;
Last edited on
Could you refrase your question? its kind of confusing.
The program is to calculate parking fees. However when I run the program it prints the statement, but still runs the program and states that the parking fee is $0 for zero minutes. I wanted to see if I can end the program if the total minutes is 0.

Thank you for your help.
you need the whole if braces like this:

1
2
3
4
5
6
7
8
9
10
11
12
if(totalMinutes==0)
{
  cout<<"You have not entered a valid number"<<endl;
  // do some other stuff when totalMinutes is zero.
}
else 
{
  // do something else
  // i.e. here is where you should calculate the parking fee
  // based on the total number of minutes entered.

}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
cout << "Enter total minutes parked: " << endl;
cin >> totalMinutes;

  if(totalMinutes != 0)
  {
        cout << "Valid number" << endl;
  }
  else 
  {
       cout << "Not valid number" << endl;
  }


Either mine or @mutexe works. Pick one.
Last edited on
Thank you
Topic archived. No new replies allowed.