Cuanta suerte tienes?

--Originally published at Adal´s Blog


Quieres probar tu surte con un divertido juego?


Para poder hacer este código me enfrente a un pequeño detalle, el hecho de que no sabia como generar números al azar, pero gracias a aprenderaprogramar.com, me dieron una ayudita de como hacerlo, se los dejo aquí ▼:



Pagina de ayuda:

Adivina el numero

--Originally published at Hensel

En el programa, se pedía que dentro del rango de 1 a 100, se escogiera un numero, el cual el usuario tiene que adivinar.Después de varios intentos, al encontrar ese numero, debe de desplegar un mensaje, que dice que has encontrado el numero y te dice en cuantos intentos lo has conseguido. Si el numero es más grande que el que tienes que adivinar, el programa te dice que es muy grande y viceversa. Para poder lograr que ese numero fuese diferente cada vez que se corre el programa, tuve que realizar una operación al primer numero que ingrese el usuario, por lo que en mi programa jamás podrás adivinar a la primera.

Utilicé el condicional If, para poder comparar el valor ingresado por el usuario y el numero correcto.archivo_000

En el desarrollo del programa, coloque una variable llamada constante,  la cual me serviría como referencia en la comparación, pero al correr el programa no pasaba de la línea 10 y decidí quitarla.


Third assignment – Pick a number

--Originally published at The Clueless Programmer

Okay so this assignment really tested me out, specially because I didn´t know anything about generating a random number or how to do it, but by reading the book (and asking a lot of questions) I figures it out. Let´s go.

The tasks asks us to make a program that thinks of a random number and then starts asking us to guess the number, telling us if we are lower or higher, once we guess it, it gets us out.

imagen1

#include <iostream>
#include <stdlib.h>//Library for the rand command
using namespace std;
int main()
{
int n1, n2;
char cond=’n’;
srand(time(NULL));//This makes the number always random
n1=rand()%101;//I use the 101 because it takes every number until the number you write
do
{
cout<<“Try to guess the number I´m thinking of”<<endl;
cin>>n2;
if (n2>n1)
{
cout<<“Your number is higher than the one I´m thinking of”<<endl;
}
else if(n2<n1)
{
cout<<“Your number is lower than the one I´m thinking of”<<endl;
}
else
{
cout<<“Congrats! You guessed it”<<endl;
cond=’s’;
}
} while(cond==’n’);
}

So okay you are confused, you see a lot of tricky stuff right? But don´t worry it will make sense, eventually.

First what you want to do is include the library that has the command for the random number generator. Then after you name your variables, you write that srand stuff, which basically what it does is change the random command so that everytime you enter the number is different. Then you write the rand command, I write 101 instead of 100 because it takes the number before the oe you write, so 0-100. Then we enter the do-while, which basically means it ill do something at first and then continue to do it while the condition isn´t fulfilled. I do the ifs and else in which I close out

Continue reading "Third assignment – Pick a number"

How to go: 0 to 100, real quick.

--Originally published at Ken&#039;s Disciple 01

Picture by Stokpic Stokpic

As you may imagine, this blog will be about WSQ03, in which we were asked to write a program that randomly picked a number from 1 to 100, ask the user to try to guess it, give him “too high” and “to low” hints and also showing the amount of guesses.

This Program is kind of challenging because in order to do this you have to use a “new” function that allows the program to choose the random number, this page may help you to learn the new functions you’ll need.

You don’t have to worry about this program, it’s actually easy once you have everything you need. All right so let’s get started:

  • Starting this program is just doing the same as usual, inside your main, you’ll have to declare your variables, you’ll need 3; one for the random number that the program will choose, one for the guessed number that the user will give and the last one is the one that will tell you the amount of times you tried to guess the number.
  • The next thing you’ll have to know is the function srand(time(0)); (for more info you can visit this page.srand() gives the random function a new seed, a starting point.

    time(0) with these you’re guaranteed your seed will be the same only once, unless you start your program multiple times within the same second.

  • then you’ll use your rand function and tell the program from which numbers you want to pick a random one, here are some examples:
    v1 = rand() % 100;         // v1 in the range 0 to 99
    v2 = rand() % 100 + 1;     // v2 in the range 1 to 100
    

    As you can see the %”…” gives you with how many numbers you want to

    Captura de pantalla 2017-01-26 a la(s) 15.27.06.png
    Captura de pantalla 2017-01-26 a la(s) 16.02.48.png
    Continue reading "How to go: 0 to 100, real quick."

Pick a number

--Originally published at estefilangarica.wordpress.com

Fourth Activity

The assignment Ken gave us was the following:

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.