Question

In: Computer Science

in C++ use loopDW.cpp below Do While Loop Exercise Get a copy of the loopDW.cpp. Add...

in C++ use loopDW.cpp below

Do While Loop Exercise

  • Get a copy of the loopDW.cpp.
  • Add a do-while loop to complete the program.
    The do-while loop will make sure that
    a valid mark will be obtained before further process.
    (hint: a event-controlled do-while loop is needed.)
  • Compile and run the program.
    Use input values: -10, 30, 59, 70, 75, 96, and 108.
  • Show the output to your lab instructor.
#include <iostream>
using namespace std;

int main()
{
   int mark;
   char grade;

   cout << "Please enter an integer mark: "  << endl;

   // Please add a do-while loop below to make sure a valid mark 
   // between [0, 100] is entered. 




   if (mark >= 85)
   {
      grade = 'A';
      cout << "Great Mark. " << endl;
   }
   else if (mark >= 75 && mark < 85) 
   {
      grade = 'B';
      cout << "Good Mark. " << endl;
   }
   else if (mark >= 65 && mark < 75) 
   {
      grade = 'C';
      cout << "Average Mark. " << endl;
   }
   else if (mark >= 50 && mark < 65) 
   {
      grade = 'D';
      cout << "You passed the class. " << endl;
   }
   else 
   { 
      grade = 'F';
      cout << "You failed the class. " << endl;
   }

   cout << "The corresponding character grade is " << grade << endl;

   return 0;
}
// end program

Solutions

Expert Solution

Code:

#include <iostream>
using namespace std;

int main()
{
   int mark;
   char grade;

   cout << "Please enter an integer mark: " << endl;
  
   do{
       //taking input from user
       cin>>mark;
       //if mark is greaterthan 100 or lessthan 0
       //then print the message
       if(mark>100 || mark<0){
           cout<<"Invalid input, marks [1 -100]"<<endl;
       }
   //this loop iterates until user enters valid marks
   }while(mark>100 || mark<0);


   if (mark >= 85)
   {
      grade = 'A';
      cout << "Great Mark. " << endl;
   }
   else if (mark >= 75 && mark < 85)
   {
      grade = 'B';
      cout << "Good Mark. " << endl;
   }
   else if (mark >= 65 && mark < 75)
   {
      grade = 'C';
      cout << "Average Mark. " << endl;
   }
   else if (mark >= 50 && mark < 65)
   {
      grade = 'D';
      cout << "You passed the class. " << endl;
   }
   else
   {
      grade = 'F';
      cout << "You failed the class. " << endl;
   }

   cout << "The corresponding character grade is " << grade << endl;

   return 0;
}
// end program

Output:

Code Screenshot:

Code Snippet:

#include <iostream>
using namespace std;

int main()
{
   int mark;
   char grade;

   cout << "Please enter an integer mark: "  << endl;
        
        do{
                //taking input from user
                cin>>mark;
                //if mark is greaterthan 100 or lessthan 0
                //then print the message 
                if(mark>100 || mark<0){
                        cout<<"Invalid input, marks [1 -100]"<<endl;
                }
        //this loop iterates until user enters valid marks
        }while(mark>100 || mark<0);




   if (mark >= 85)
   {
      grade = 'A';
      cout << "Great Mark. " << endl;
   }
   else if (mark >= 75 && mark < 85) 
   {
      grade = 'B';
      cout << "Good Mark. " << endl;
   }
   else if (mark >= 65 && mark < 75) 
   {
      grade = 'C';
      cout << "Average Mark. " << endl;
   }
   else if (mark >= 50 && mark < 65) 
   {
      grade = 'D';
      cout << "You passed the class. " << endl;
   }
   else 
   { 
      grade = 'F';
      cout << "You failed the class. " << endl;
   }

   cout << "The corresponding character grade is " << grade << endl;

   return 0;
}
// end program

Related Solutions

This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your...
This is for C++ You must use either a FOR, WHILE, or DO-WHILE loop in your solution for this problem. Write a quick main console program to output the following checker pattern to the console: #_#_#_#_# _#_#_#_#_ #_#_#_#_# _#_#_#_#_ #_#_#_#_#
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Open Average Test Scores while loop, comment out the while loop and add a for loop...
Open Average Test Scores while loop, comment out the while loop and add a for loop that averages 4 test scores. Code C# While loop code using System; class Program { static void Main() { int count = 0, total = 0, number;    while (count < 3) { Console.Write("Enter a number: "); number = Convert.ToInt32(Console.ReadLine()); total += number; count++; }    double average = total / 3.0; Console.Write("Average = " + average.ToString("####0.00")); } }
Modify the previous program to use the Do-While Loop instead of the While Loop. This version...
Modify the previous program to use the Do-While Loop instead of the While Loop. This version of the program will ask the user if they wish to enter another name and accept a Y or N answer. Remove the "exit" requirement from before. Output: Enter the full name of a person that can serve as a reference: [user types: Bob Smith] Bob Smith is reference #1 Would you like to enter another name (Y or N)? [user types: y] Enter...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks...
Do the following lab by while or Do-while loop. question: Write a c++ program that asks students to enter 3 valid grades and then calculate the average and print it. if the user enters the invalid grade you should print the error message and get the new grade. Hint1: each time your program ask the following question: "Do you want to calculate another average?" and if the answer to this question is "Y" or "y" then you should continue. Hint2:...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the for loop, and selection. Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters a 0 or a negative number the program should exit with a message to the user indicating they chose to exit. If...
Hello, I Have create this code and Tried to add do while loop but it gives...
Hello, I Have create this code and Tried to add do while loop but it gives me the error in string answar; and the areas where I blod So cloud you please help me to do ( do while ) in this code. // Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should...
Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same output as the original code below. int total = 0; while(total<100) { System.out.println("you can still buy for"+(100-total)+"Dollars"); total=total+5; }
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to...
Write a program in C++ coding that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4,...
C programming. Explain by taking a programming example how do while loop is different from while...
C programming. Explain by taking a programming example how do while loop is different from while loop?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT