WSQ03

What to do:

Write a program that picks a random integer in the range of 1 to 100.

There are different ways to make that happen, you choose which one works best for you.

It then prompts the user for a guess of the value, with hints of ’too high’ or ’too low’ from the program.

The program continues to run until the user guesses the integer. You could do something extra here including telling there user how many guesses they had to make to get the right answer.

You might want to check that your program doesn’t always use the same random number is chosen and you should also split your problem solving into parts. Perhaps only generate the random number and print that as a first step.

Progress:

First we looked for the way to create the random number, we found a good post that helped us a lot. Then we started reading a little more about counters and the while function that was the one that made me more suitable for my program. After a bit of analysis finally came out the program but I have a fault in the counter that I did not know how to remove it, I hope Ken can explain to me.

captura-de-pantalla-2017-02-01-a-las-23-39-51

Sources of research:

http://blog.martincruz.me/2012/09/obtener-numeros-aleatorios-en-c-rand.html

http://www.aprenderaprogramar.com/index.php?option=com_content&view=article&id=931:bucles-en-lenguaje-c-estructura-de-repeticion-condicion-contador-ejemplos-tabla-de-multiplicar-cu00533f&catid=82:curso-basico-programacion-lenguaje-c-desde-cero&Itemid=210

Code:

#include <stdlib.h>
#include <time.h>
#include<iostream>
using namespace std;
int main() {
int num,resp,intentos;
srand(time(NULL));
num=1+rand()%(101-1);
do {
std::cout << “ya estoy listo para jugar” << ‘\n’;
std::cout << “¿cual numero crees que tengo para ti?” << ‘\n’;
std::cin >> resp;
intentos++;
if (num<resp) {
std::cout << “lo siento, pero tu numero es muy alto” << ‘\n’;
}
if (num>resp) {
std::cout << “lo siento, pero tu numero es muy bajo” << ‘\n’;
}
} while(num!=resp);
std::cout << “lo lograste!!!, el numero mágico es:” <<num<< ‘\n’;
std::cout << “lo obtuviste en: ” <<intentos<<“intentos”<< ‘\n’;
return 0;
};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s