# guessing game help

Page 1 of 1

## 4 Replies - 865 Views - Last Post: 17 March 2009 - 08:41 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=93552&amp;s=4ad68228b1940dd211edaf8afaae364c&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mppaki

Reputation: 0
• Posts: 8
• Joined: 17-March 09

# guessing game help

Posted 17 March 2009 - 07:34 PM

Hi i need help with my code,

im doing a guessing game for my school project and i cant get it to do what i want it to do.

im trying to make it so that 50 goes higher by h and lower by l and if i press r, it will say i found your answer and end the program.

im using visual c++ 6.0.

```//project name:
//project date:
//project description:

#include <iostream.h>

main()
{
int x= 50, guess;
cout << "Think of a number 1-100!" << '\n';
do
{
cout << "Is the number "<< x << "?(H, L, R)" << '\n';
cin >> x;

switch(x)
{
case 'H':
guess = x * 1.25;
break;
case 'L':
guess = x / 0.5;
break;
case 'R':
guess = x;
break;
}
}
while (x != 0);
return 0;
}

```

This post has been edited by mppaki: 17 March 2009 - 07:49 PM

Is This A Good Question/Topic? 0

## Replies To: guessing game help

### #2 n8wxs

• --... ...-- -.. . -. ---.. .-- -..- ...

Reputation: 972
• Posts: 3,878
• Joined: 07-January 08

## Re: guessing game help

Posted 17 March 2009 - 08:01 PM

guess = x / 0.5; Dividing by 1/2 is the same as multiplying by 2. X will never be lower.

### #3 mppaki

Reputation: 0
• Posts: 8
• Joined: 17-March 09

## Re: guessing game help

Posted 17 March 2009 - 08:12 PM

```//project name:
//project date:
//project description:

#include <iostream.h>

main()
{
int x= 50, guess;
cout << "Think of a number 1-100!" << '\n';
do
{
cout << "Is the number "<< x << "?(H, L, R)" << '\n';
cin >> x;

switch(x)
{
case 'H':
guess = x * 1.25;
break;
case 'L':
guess = x / 2;
break;
case 'R':
guess = x;
break;
}
}
while (x != 0);
return 0;
}

```

anything else you can help to get my H to make 50 go higher L to make 50 go lower and R to say its the right number?

### #4 n8wxs

• --... ...-- -.. . -. ---.. .-- -..- ...

Reputation: 972
• Posts: 3,878
• Joined: 07-January 08

## Re: guessing game help

Posted 17 March 2009 - 08:23 PM

You are assigning "guess" the modified value of "x": guess = x * 1.25;. X never changes.

I think what you want is
```...
cout << "Is the number "<< x << "?(H, L, R)" << '\n';
cin >> guess;

switch(guess)
{
case 'H':
x *= 1.25;
break;
...

```

I would make "guess" a char rather than an int.

This post has been edited by n8wxs: 17 March 2009 - 08:24 PM

### #5 mppaki

Reputation: 0
• Posts: 8
• Joined: 17-March 09

## Re: guessing game help

Posted 17 March 2009 - 08:41 PM

```//project name:
//project date:
//project description:

#include <iostream.h>

main()
{
int x= 50;
char guess;
cout << "Think of a number 1-100!" << '\n';
do
{
cout << "Is the number "<< x << "?(h, l, r)" << '\n';
cin >> guess;

switch(guess)
{
case 'h':
x = x * 1.25;
break;
case 'l':
x = x / 1.25;
break;
case 'r':
x;
break;
}
}
while (x != 0 && x <= 100);
return 0;
}

```

i have a few more questions, what would be the best equation to use to go higher and lower and how can i make so when it hit H, and lets say its at 99 that it would go 100 and not end the program? right now it just ends the program if it goes to low. the same for 0.

This post has been edited by mppaki: 17 March 2009 - 08:43 PM