Search

# Blogging through my thoughts

### #WSQ03

Good morning!

The third task was to create a program that picks a random integer in the range of 1 to 100. After that , the game starts when the user has to guess which number does the program picked, with hints of ’too high’ or ’too low’.

The program continues to run until the user guesses the integer.

¿How many guesses they had to make to get the right answer?

___________________________________________________________________

The resources that helped me were:
-How to think like a computer scientist.

-cplusplus.com

-cppreference.com

-Programming hub, mobile app.

Until next time!

This is my third program, created using Cygwin and Atom.

The task was to create a program that picks a random integer in the range of 1 to 100. After that , the game starts when the user has to guess which number does the program picked, with hints of ’too high’ or ’too low’.

The program continues to run until the user guesses the integer.

-How many guesses they had to make to get the right answer.

The resources that helped me were:
-How to think like a computer scientist.

-cplusplus.com

-cppreference.com

-Programming hub, mobile app.

Here you will find my code and some captures:

#include <iostream>
#include <stdlib.h>   // srand , rand
#include <time.h>     // time
using namespace std;

int main(){
int secret , guess, attempts;

cout << “This program picks a random integer in the range of 1-100.” << endl;
cout << “***In order to win , you need to guess the number***” << endl;

srand (time(NULL));               // Initialize random seed
secret = rand() % 100 + 1;

do {
cout << “Write your guess:”<< endl;
cin >> guess;
attempts=attempts+1;

if (secret<guess){
cout << “The secret number is lower.” << endl;
}
else if (secret>guess){
cout << “The secret number is higher.” << endl;
}
} while (secret!=guess);

cout << “You won , congratulations!” << endl;
cout << “It took you ” << attempts << ” attempts.” << endl;
return 0;
}

Until next time.

°Luis Felipe Garate Moreno.