Search

Blogging through my thoughts

Felipe GM : ¡Be welcome to my personal and academical blog!

Tag

#WSQ03

WSQ03 – Pick a number.

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.

I added some extra steps, because I wanted to show more information to the users , like:

¿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.

WSQ03ATOM1

WSQ03ATOM2
Atom code.
WSQ03UBUNTU
Ubuntu commands.

WSQ03MASTERY

Until next time!

WSQ 03 – Pick a number.

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.

I added some extra steps, because I wanted to show more information to the users , like:

-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:

wsq03-code
Atom code.

#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;
}

wsq03-cygwin
Running on Cygwin.

wsq03-topics

masterytopics1
Mastery topics involved.

 

Until next time.

°Luis Felipe Garate Moreno.

 

Website Powered by WordPress.com.

Up ↑