#include
#include
#include
#include
#include
#include
using namespace std;
void message(void)
{
cout << "You have run out of tries. \n Game Over";
}
int main()
{
const double g = 9.81; // gravity acceleration
string cH0, cEps, cN;
cout << "Enter the initial height, h0\t\t\t: ";
cin >> cH0;
cout << "Enter the rebound coefficient, eps (0 cin >> cEps; cout << "Enter the number of rebounds, n (>=0)\t\t: “; cin >> cN; cout << endl; double dH0 = atof(cH0.c_str()), dEps = atof(cEps.c_str()), s, s1, H = dH0; int N = atoi(cN.c_str()); for (int I = 0; I <= N; I++) { cout << "The height after " << setw(3) << I << " rebounds is "; cout << setw(7) << setprecision(4) << H << endl; s = sqrt(2 * g*H), s1 = dEps*s; // the new speed H = (s1*s1) / (2 * g); // the new height } cout << endl; srand((unsigned int)time(NULL)); int r = rand() % 100 + 1; int attempts = 0; int guess; while (true) { cout << "Enter a number between 1 and 100 (" << 7 - attempts << " attempt(s) left): "; cin >> guess; if (attempts >= 7) { break; } if (guess > r) { cout << "Too high! Try again.\n"; } else if (guess < r) { cout << "Too low! Try again.\n"; } else { break;} attempts++; } if (attempts > 7) { message(); } else { cout << "Congratulations!! " << endl; cout << "You got the right number in " << attempts << " attempt(s)!\n"; } system(“pause”); return 0; } op
In one file:
Smarthinking 24/7 Online
Tutoring
Part A
Redo Project 3. This time when the user enter n, ho, esp, your code will print the height after each rebound till n. This means if the user enters n-4, your
code will print:
After rebound #1, the height of the ball is: …
After rebound #2, the height of the ball is: …
After rebound #3, the height of the ball is: …
After rebound # 4, the height of the ball is: …
Part B
Create a game that asks the user to guess the number between 0 and 100 automatically generated by your C++ code.
Requirements:
The user has 7 attempts available to find the number
The game displays clues to help the user guess the number at each attempt (go lower or higher)
Your code should not use functions to be seen in the next module where you will rewrite this program)
Your code should use at least one control structure
Your code should use a random number generator to generate a new random number to guess for each game
Program presentation and display will be 30% of your grade while functionalities will represent 70%
Submit your code .cpp file and e in pdf file
random gen.cpp
By submitting this
paper, you agree that you are submitting your
paper to be used and stored as part
of the SafeAssign services in accordance with the Blackboard Privacy Policy, (2)
that your institution may use your paper in accordance with your institution’s policies; and (3) that your use of SafeAssign will be without recourse against Blackboard Inc. and its affiliates.
Institution Release Statement
This feature of Blackboard will check your paper for plagiarism. It will also protect your paper from plagiarism by others