Question

In C++ Programming, Try using loops only. This lab demonstrates the use of the While Loop...

In C++ Programming, Try using loops only.

This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You will want to write a refined algorithm for both to see the logic differences.

Lab 7 Part a: Using a While Loop, write the code that does the following: Prompts the User for a score between 0 and 100 (inclusive). Repeats the prompt until the User enters a valid number within the specified range. When the user enters a number within the valid range, let them know with an output statement.

Lab 7 Part b: Using a Do While Loop, write the code that does the following: Prompts the User for a score between 0 and 100 (inclusive). Continues to prompt for scores until the User enters a valid number within the specified range. When the user enters a number within the valid range, let them know with an output statement.

Include the following in your programs: 1. A refined algorithm for each looping structure.

2. The code to pause the screen when displaying output: system ("pause");

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

using namespace std;

int main()
{
   int num=-1;//initialized to run while loop the first time
   while (num<0 || num >100)
   {
       cout<<"Enter a score between 0 and 100 (inclusive): ";
       cin>>num;
   }
   cout<<"You entered: "<<num<<endl;
  
   do
   {
       cout<<"Enter a score between 0 and 100 (inclusive): ";
       cin>>num;
   }while(num<0 || num >100);
   cout<<"You entered: "<<num<<endl;
   system("pause");
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
In C++ Programming, Try using loops only. This lab demonstrates the use of the While Loop...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please do this in C++ using only for loops, while loops, and do while loops. No...

    Please do this in C++ using only for loops, while loops, and do while loops. No arrays. Use for loop, while loop, and do while loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1-256 Note: See Appendix for number systems The program should print the results to the Console without using any string formats Design Details: The Main program should prompt the user for...

  • Answer using programming in C only. 6 pts Use a while loop to complete the following:...

    Answer using programming in C only. 6 pts Use a while loop to complete the following: Prompt the user to enter integers one by one, until the user enters a negative number to stop Calculate the sum and the average of all the numbers entered by the user Print the sum and the average onto the screen after the loop. Declare and initialize all variables. Be sure to keep a count of the numbers entered for the average calculation

  • need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that...

    need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...

  • C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an...

    C++ please 27.5 Loops (nested)**: Sum a given number of integers A user will enter an initial number, followed by that number of integers. Output those integers' sum. Repeat until the initial number is O or negative. Ex: If the user enters 3 96 1 0, the output is 16 Ex: If the user enters 396125 3 0, the output is 16 Hints: Use a while loop as an outer loop. Get the user's initial number of ints before the...

  • Using C language to solve the problem below: 3. (5 pts) Construct a do-while () loop,...

    Using C language to solve the problem below: 3. (5 pts) Construct a do-while () loop, which continues to display the following menu: 1. Play game 2. Display score 3. Deposit funds 4. Exit and prompt the user for an option, while the option entered by the user is not in the range 1- 4, inclusive. Note: you are constructing an input validation loop. Show all variable declarations.

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • In Python Exercise – For & While Loops Create a new file called loops.py and use...

    In Python Exercise – For & While Loops Create a new file called loops.py and use it for all parts of this exercise. Remember the difference between input and raw input? Be sure to test your code for each part before moving on to the next part. Write a program using a for loop that calculates exponentials. Your program should ask the user for a base base and an exponent exp, and calculate baseexp. Write a program using a while...

  • Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

    Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...

  • Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is...

    Objectives: Learn how to use the C++ while and for loops. Instructions: A perfect number is a positive integer greater than 1 that is equal to the sum of the positive integer numbers, including 1 but not including itself, that evenly divide into it. First, you should prompt the user for a number. Next, you should indicate if the number is a perfect number or not. Finally, you should list the numbers that evenly divide into the number entered and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT