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...
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The...
In C++ and input code using the template below Get a copy of the caseswitch.cpp. The purpose of the program is to demonstrate how to use Switch statement. Complete the for loop so that the program will ask the user for 6 input grades. Compile and run this C++ program. Use input value A, B, C, D, E, and F. Notice there is no output for B and E. Add cases for them. B is "Good Work." Add a case...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
C++ while loop Exercise Write a program that continues to ask the user to enter any...
C++ while loop Exercise Write a program that continues to ask the user to enter any set of numbers, until the user enters the number -1. Then display the total sum of numbers entered and their average. (note that you need to define a counter that counts how many numbers so the average = (sum/n) where n is your counter total. #include <iostream> using namespace std; int main() { int number, n=0, sum=0; cout << "Enter a number to start...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT