Question

Assignment (Must be completed and submitted prior to your lab3 session) Create a do-while loop that displays a random number on the screen, and then displays a message (in a new line) asking the user if he wishes to see another random number. If the user responds with a y or a ‘Y character, then the program shall repeat (i.e. outputs another random number and asks the user again). If the user responds with HINTS: To generate a random number you shall include the header file stdlib.h (#include <stdlib.h>) and use the function randO (e.g. myvar-randO:) I recommend using a do-while loop, but you can use any loop that you are comfortable with. · .Code your algorithm in C++ .Debug your code; If it did not work properly, ask why (from a high level) did it not work? Is it an algorithmic or coding error? Use the debugger to identify the root-cause and fix your code. What to hand in: . The actual code in a .cpp file.

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

Dear Student,

here i have written the C++ code as per the requirement.

Please note the below program has been tested on ubuntu 16.04 system and compiled using g++ compiler.

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

Program:

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

//header file declration

#include<iostream>

#include<stdlib.h>

//namespace declration

using namespace std;

//start of the main function

int main()

{

//variable data type declration

int myvar;

char c;

//start of do while loop

do

{

//generatea a random number and store it in myvar

myvar = rand();

//dsiplay random number

cout<<"Random number is: "<<myvar<<endl;

//ask to enter wish

cout<<"Do you want to see another random number 'y' or 'Y' : ";

cin>>c;

//if c is not valid
//exit the program

if(c != 'y' && c != 'Y')

{

cout<<"Exiting the program.."<<endl;

break;

}

}while(c == 'y' | c == 'Y');


return 0;

}//end of the main function


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

here i have attached the output as a screen shot.

Output:

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

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

Kindly Check and Verify Thanks...!!!

Add a comment
Know the answer?
Add Answer to:
Assignment (Must be completed and submitted prior to your lab3 session) Create a do-while loop that...
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
  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • For this assignment, you will apply what you learned in analyzing for, while, and do-while loops...

    For this assignment, you will apply what you learned in analyzing for, while, and do-while loops by writing these statements yourself. The Java™ program you write should do the following: Display a pyramid of asterisks onscreen (i.e., a nested for loop) Display the integers 10 to 1 in decreasing order, one number per line (i.e., a while/do-whlie loop) Add 7 until the sum becomes greater than 157, at which point the program should display both the sum and the number...

  • The programming language has to be C. Do you remember rand()? Do you remember how it...

    The programming language has to be C. Do you remember rand()? Do you remember how it can use srand() for a seed? Did you know that rand uses that seed as the initial state of their random number generator. Did you know that a random number generator is really a deterministic sequence generator? Yeah! So your next random number might be calculated using a recursive equation like: rand_n = rand_(n-1) * coeffecient1 + coeffecient2 That is the random number produced...

  • Write a complete C++ program that creates a monthly bill for the text messaging. Your cell...

    Write a complete C++ program that creates a monthly bill for the text messaging. Your cell phone company provides the following three text messaging plans. Package A: Two Thumbs.   For $9.95 per month, 100 text messages are allowed. Additional text messages are 15 cents each. Package B: All Thumbs. For $14.95 per month, 200 text messages are allowed. Additional text messages are 10 cents each. Package C: Lightning Thumbs. For $19.95 per month, unlimited text messaging is provided. State sales...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1....

    Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1. You program will read in a student’s first name. The same will be done for the student’s last name. Your program will use respective methods (described below) to accomplish this. 2. Your program will then read in three quiz scores, respectively. This should be done by using the same method three times. This method is described below. 3. Your program will then calculate the...

  • For this c++ assignment, Overview write a program that will process two sets of numeric information....

    For this c++ assignment, Overview write a program that will process two sets of numeric information. The information will be needed for later processing, so it will be stored in two arrays that will be displayed, sorted, and displayed (again). One set of numeric information will be read from a file while the other will be randomly generated. The arrays that will be used in the assignment should be declared to hold a maximum of 50 double or float elements....

  • does anyone know how to do this? C++ Your task for this assignment is to use...

    does anyone know how to do this? C++ Your task for this assignment is to use C++ language to implement an insertion sort algorithm. 1. Implement an insertion sort with an array to sort 10 arbitrary numbers using the C++ programming language. The program initializes an array with 10 random 3-digit positive integers. The program then sorts the numbers in the array using the insertion sort algorithm. 2. The program displays the original values in the array before the sort...

  • Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless...

    Please do it like someone wouldve done it as a beginer programer. Dont use pointer unless it asking for. /* Write a program designed to get ages and heights from the user, then find the average age, average height, and average age/height ratio. */ #include <stdlib.h> #include <stdio.h> #define MAXNUM 50 typedef struct person { int age; double height; } Person; int getData(Person people[], int max) /* Get the data from the user and put it in an array of...

  • I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs ca...

    I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...

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