Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write an IF statement that prints the message “ The number is valid ” if the

ID: 3668108 • Letter: 1

Question

1. Write an IF statement that prints the message “The number is valid” if the variable temperature is within the range -50 through 150 (inclusive)

2. Convert the following IF – ELSE – IF statement into a SWITCH statement –        (3 points)

if (choice == 1)

{

            cout << fixed << showpoint << setprecision(2);

}

else if (choice == 2 || choice == 3)

{

            cout << fixed << showpoint << setprecision(4);

}

else if (choice == 4)

{

            cout << fixed << showpoint << setprecision(6);

}

else

{

            cout << fixed << showpoint << setprecision(8);

}

3. Find the errors and correct them

// This program uses an if/else if statement to assign a letter grade

// (A, B, C, D or F) to a numeric test score.

#include <iostream>

using namespace std;

void     main( )

{

            int testScore;

            cout << “Enter your test score and I will tell you” << endl;

            cout << “the letter grade you earned: “;

            cin >> testScore;

            if (testScore < 60)

                        cout << “Your grade is F.” << endl;

            else if (testScore < 70)

                        cout << “Your grade is D.” << endl;

            else if (testScore < 80)

                        cout << “Your grade is C.” << endl;

            else if (testScore < 90)

                        cout << “Your grade is B.” << endl;

            else

                        cout << “That is not a valid score.” << endl;

else if (testScore <= 100)

                        cout << “Your grade is A.” << endl;

}

Explanation / Answer

Multiple Questions : Answering 1st .

if (temperature > -50 && temperature <= 150) // 150 inclusive

     cout<<"The number is valid";

---------------------------------------------------

if (temperature > -50 && temperature <= 150)

     cout<<"The number is valid";

else

    cout<<"The number is invalid";