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.

Sources of research:

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

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