Tuesday, March 31, 2015

Fitness level --- example for if else

Script

// This is a program that asks a user for their input on how much time
// he or she took to walk 5 miles.  Based on the input information and the
// table below, the program will print the appropriate message.
// More than 90 minutes   You are very slow, need to get fitter
// Between 75 and 90 minutes   Your fitness level needs improvement
// Between 60 and 74 minutes   You are quite fit, doing well
// Between 45 and 59 minutes   You are extremely fit, keep it up
// Lesser than 45 minutes  Oh my goodness, you are super fit !!!
// Lesser than 0 minutes   Invalid entry, program will terminate.

#include <iostream>
using namespace std;

main()
{
        int minutes=0;
        cout << "Enter how many minutes you took to walk five miles: ";
        cin >> minutes;

        if (minutes < 0)
        {
        cout << "Invalid entry, program will terminate." << endl;
        return 0;
        }

        else if (minutes < 45)
        {
        cout << "Oh my goodness, you are super fit !!!" << endl;
        }

        else if (minutes >= 45 && minutes <= 59)
        {
        cout << "You are extremely fit, keep it up" << endl;
        }

        else if (minutes >= 60 && minutes <= 74)
        {
        cout << "You are quite fit, doing well" << endl;
        }

        else if (minutes >= 75 && minutes <= 90)
        {
        cout << "Your fitness level needs improvement" << endl;
        }

        else
        {
        cout << "You are very slow, need to get fitter" << endl;
        }

}


Execution

Enter how many minutes you took to walk five miles: -75
Invalid entry, program will terminate.


Enter how many minutes you took to walk five miles: 37
Oh my goodness, you are super fit !!!


Enter how many minutes you took to walk five miles: 150
You are very slow, need to get fitter

Enter how many minutes you took to walk five miles: 47
You are extremely fit, keep it up

Enter how many minutes you took to walk five miles: 63
You are quite fit, doing well



No comments:

Post a Comment