Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

Ta Email

Download Compiler

Final Project

Lab Notes

Office Hours

Schedule

Syllabus

Announcements

Check Grades

 

CSci 1113 Home

 
 

Printer-friendly version

 
Nested if-else Statement

% cat fish_if.cpp
#include<iostream>
using namespace std;

int main()
{
  char resident;
  int age, fee;

  cout << "Enter the age of the person: ";
  cin >> age;

  cout << "Enter y if the person is a resident, n otherwise: ";
  cin >> resident;

  fee = 50;

  if(resident == 'y')
  {    
     if (age >= 65 )
       fee = 25;
  }
  else
    fee = 100;

  cout << "The fishing license fee is $" << fee << endl;

  return 0;
}

What happens if you remove the braces in the if-else statement?  

    TRY IT!

 
The University of Minnesota is an equal opportunity educator and employer.
CSci 1113: C++ Programming