Ivan asked us to build a guessing game based on the knowledge that we have. I worked hard, searching to find a solution. All roads may lead to Rome, but my solution did not produce the exact result as Ivan’s did. In fact, it didn’t even do what I wanted it to do.
I have two questions:
- I spent too much time trying to hide the number that player one put into the system. Is that possible at my beginner level? If so, is there a tutorial that you can link?
- As you will see, I chose a “do while” loop, and wanted five guesses. It iterated the false answers twice, then ended the loop. I tried moving the curlies around, but this didn’t work. Any help??
Here’s the code:
// Created by Donnie Starkey on 9/10/20.
// Copyright © 2020 Donnie Starkey. All rights reserved.
//
#include
#include <stdlib.h>
int main(int argc, const char * argv[])
{
int number {};
std::cout <<“give me a number”<< ‘\n’;
std::cin>> number;
int guess{};
do {
std::cout<<“guess the number!”;
std::cin>> guess;
if (number==guess)
{
std::cout<< “good job!!!”;
}
else if (number>guess)
{
std::cout<<"your guess is too low " <<’\n’;
}
else if (number<guess)
{
std::cout<< “your guess is too high!!” <<’\n’;
}
} while (guess <5);
guess++;
}
Here’s the code: