mercredi 3 octobre 2018

Why are all if-else statements printing no matter the input?

When inputting any letter (F, R, or G) every if statement prints in the compiler. Im not sure as to why this is the case but some answers would be nice!

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
cout << "Fall 2018 Automated \"Bruin\" Golf Course Sprinkler System" << endl;
cout << endl << "What is the temperature in degrees(F)? ";
cin >> tmp;
cout << "How much precipitation today (in inches)? ";
cin >> precip;
cout << "The Golf Course grass divisions are F-Fairways, R-Rough, G-Greens.";
cout << endl << "Which do you choose (FRG)? ";
cin >> frg;

if (frg == 'R' && precip < 0.835 && tmp > 38)
    {
        cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
        cout << "The Rough on the Golf Course will be watered.";
    } else
        {
            cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
            cout << "The Rough on the Golf Course will NOT be watered.";
        }

if (frg == 'F' && precip < 0.525 && tmp > 38)
    {
        cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
        cout << "The Fairways on the Golf Course will be watered.";
    } else
        {
            cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
            cout << "The Fairways on the Golf Course will NOT be watered.";
        }

if (frg == 'G' && precip < 0.325 && tmp > 38)
    {
        cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
        cout << "The Greens on the Golf Course will be watered.";
    } else
        {
            cout << endl << "Given the temperature is " << tmp << " degrees and " << precip << " inches of precipitation today." << endl;
            cout << "The Greens on the Golf Course will NOT be watered.";
        }
return 0;
}

Even when i input R when asked for the frg variable, all the if statements are printed in the compiler. Please help!

Thank you.

Aucun commentaire:

Enregistrer un commentaire