Write a program that generates a random number between 1 and 100 and asks the user...
50.1K
Verified Solution
Question
Programming
Write a program that generates a random number between 1 and100 and asks the user toguess what the number is. If the user’s guess is higher thanthe random number, the programshould display “Too high, try again.†If the user’s guess islower than the random number, theprogram should display “Too low, try again.†The programshould use a loop that repeats untilthe user correctly guesses the random number. Your programshould also keep a count of thenumber of guesses that the user makes. When the user correctlyguesses the random number,the program should display the number of guesses.Style guidelines#include directives must follow header comments, before therest of the program.Variable names:--must be meaningful--loop index names can be simple (i, j, k, etc)--The initial letter should be lowercase, following wordsshould be capitalized, no other caps or punctuation (ie:weightInPounds). This is called \"camel case\".Named constants:—use for most numeric literals (including array sizes). —nameshould be all capitals with underscores:
const double TAX_RATE = 0.0675;—should occur near the top of the program (not insidefunctions).Line length of source code should be no longer than 80characters (no wrapping of lines).Indentation:--Use 2-4 spaces (but be consistent throughout your program).--Indent blocks, within blocks, etc.--Use blank lines to separate sections.Comments for variables:All variable declarations should be commented asfollows:int rank; // numeric value for a card, A=1, J=11, Q=12,K=13
Comments for functions:Function definitions should be commented to describe what itdoes, what the parameters are, and what the function returns (whenappropriate). See the template and the example below. If thefunction body contains more than about five statements, thereshould be comments to describe the various sections of code in thefunction body.Template://***********************************************************// function name: short description of what the function does.//// param-1 description of first parameter (if any)// param-2 description of second parameter (if any)// (remaining params, if any)// returns: description of what function returns (if not void)//***********************************************************Example://***********************************************************// getBestPlayer: determines which player scored the mostpoints// p the array of player information// size the number of players in the array// returns the name of player who scored the most points//***********************************************************string getBestPlayer(Player p[], int size) {// function body goes here}In-code comments:DO NOT comment every line of code! In general, try to avoidusing comments that describe WHAT the code is doing. These areredundant (we can just read the code). Comments that explain WHYthe code is doing what it is doing are more helpful. Try tominimize in-code comments, and write readable code instead.Follow these recognized good programming practices:The grader may deduct for these issues:
1. Useappropriatedatatypes:
double populationSize; // you cannot have a fractional amount
 // of people like 2008.55, use int

2. Avoidduplicatecode(don’tcopy,pasteandmodify):
if (monthlySales > 3000) {
cout << “Commission: $\" << price * 0.25 <}
else {
cout << “Commission: $\" << price * 0.29 <better:
double rate;
if (monthlySales > 3000) {
 rate = 0.25;
}
else {
rate = 0.29;cout << “Commission: $\" << price * rate <3. Donotuseuninitializedvariables:
int total; //should be initialized to 0;
 for(..;..;..)
total = total + x; //on first use, total has garbage init
4. Useanamedconstantforanarraysize:
const int SIZE = 100; //NOT: int SIZE;
 . . .
double myArray[SIZE];
5. Avoidoutofboundsarrayaccess:
 for example:
for (int i=0; i<=SIZE; i++) { // when i == SIZE it goes
// beyond the end of the array
. . . myArray[i] . . .
 }
6.Donotuseglobalvariables(butglobalnamedconstantsaregood).
7. Usereferenceparametersonlywhennecessary.
Answer & Explanation
Solved by verified expert
3.8 Ratings (395 Votes)
NOTE Change filename author name and date in headercommentProgram starts from hereH FILENAME randomnumguesscpp AUTHOR
See Answer
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
- Unlimited Question Access with detailed Answers
- Zin AI - 3 Million Words
- 10 Dall-E 3 Images
- 20 Plot Generations
- Conversation with Dialogue Memory
- No Ads, Ever!
- Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member
Other questions asked by students
Calculus
1.2K views
Find the average rate of change on the given interval 1 s t t t...
Mechanical Engineering
1.2K views
Biology
1.2K views
12 Charles Darwin recognized that beetles are about the most numerous and diverse animals on...
Physics
1.2K views
O 85 a wire as shown in the figure is then which of the following...
Geometry
1.2K views
Find the volume of the prism 13 in OA 39 in OB 2184 in OC...
Basic Math
1.2K views
Show that if is an integer multiple of 7, then sin(2x) = 2 sin(x).Hint:Graph the...
Statistics
1.2K views
study The Physicians Health Study involved 22 071 male physicians Based on random selections 11...
Algebra
1.2K views
A Math 110 student decides to make quarterly payments of $2,500 into a retirement account...
Algebra
1.2K views
The distance formula may be written as Select one O a D XB XA YB...
Accounting
1.2K views
TufStuff, Inc., sells a wide range of drums, bins, boxes, and other containers that are...
Accounting
1.2K views
StudyZin's Question Purchase
1 Answer
$0.99
$1.99
(Save $1 )
One time Pay
- No Ads
- Answer to 1 Question
- Get free Zin AI - 50 Thousand Words per Month
Best
Unlimited
$4.99*
$9.99
(Save $5 )
Billed Monthly
- No Ads
- Answers to Unlimited Questions
- Get free Zin AI - 3 Million Words per Month
*First month only
Free
$0
- Get this answer for free!
- Sign up now to unlock the answer instantly
You can see the logs in the Dashboard.
Answer & Explanation Solved by verified expert
Get Answers to Unlimited Questions
Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!
Membership Benefits:
- Unlimited Question Access with detailed Answers
- Zin AI - 3 Million Words
- 10 Dall-E 3 Images
- 20 Plot Generations
- Conversation with Dialogue Memory
- No Ads, Ever!
- Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Other questions asked by students
Find the average rate of change on the given interval 1 s t t t...
12 Charles Darwin recognized that beetles are about the most numerous and diverse animals on...
O 85 a wire as shown in the figure is then which of the following...
Find the volume of the prism 13 in OA 39 in OB 2184 in OC...
Show that if is an integer multiple of 7, then sin(2x) = 2 sin(x).Hint:Graph the...
study The Physicians Health Study involved 22 071 male physicians Based on random selections 11...
A Math 110 student decides to make quarterly payments of $2,500 into a retirement account...
The distance formula may be written as Select one O a D XB XA YB...
TufStuff, Inc., sells a wide range of drums, bins, boxes, and other containers that are...
StudyZin's Question Purchase
1 Answer
$0.99
(Save $1 )
One time Pay
- No Ads
- Answer to 1 Question
- Get free Zin AI - 50 Thousand Words per Month
Unlimited
$4.99*
(Save $5 )
Billed Monthly
- No Ads
- Answers to Unlimited Questions
- Get free Zin AI - 3 Million Words per Month
*First month only
Free
$0
- Get this answer for free!
- Sign up now to unlock the answer instantly
You can see the logs in the Dashboard.