prints the grade for an input test score: using the else if construct


#include <iostream.h>
void main()
{
  int score;
  cout << "Enter your test score: ";
  cin >> score;
  if (score > 100)
    cout << "Error: that score is out of range.\n";
  else
    if (score >= 90)
        cout << "Your grade is an A.\n";
    else
         if (score >= 80)
        cout << "Your grade is a B.\n";
         else
         if (score >= 70)
             cout << "Your grade is a C.\n";
         else
             if (score >= 60)
            cout << "Your grade is a D.\n";
             else
            if (score >=  0)
               cout << "Your grade is an F.\n";
            else
               cout << "Error: that score is out of range.\n";
}

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

//prints the grade for an input test score:  Using the else if construct
#include <iostream.h>
void main()
{
  int score;
  cout << "Enter your test score: ";
  cin >> score;
    if (score > 100)
        cout << "Error: that score is out of range.\n";
    if((score >= 90)&&(score<=100))
        cout << "Your grade is an A.\n";
    if((score >= 80)&&(score <= 90))
        cout << "Your grade is a B.\n";
    if((score >= 70)&&(score <= 80))
        cout << "Your grade is a C.\n";
    if((score >= 60)&&(score <= 70))
        cout << "Your grade is a D.\n";
    if((score >= 0)&&(score <= 60))
        cout << "Your grade is an F.\n";
}


0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|