4 Replies - 892 Views - Last Post: 17 March 2009 - 08:41 PM Rate Topic: -----

#1 mppaki   User is offline

  • New D.I.C Head

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

guessing game help

Post icon  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:
//your name
//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   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 mppaki   User is offline

  • New D.I.C Head

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

Re: guessing game help

Posted 17 March 2009 - 08:12 PM

//project name:
//project date:
//your name
//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?
Was This Post Helpful? 0
  • +
  • -

#4 n8wxs   User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#5 mppaki   User is offline

  • New D.I.C Head

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

Re: guessing game help

Posted 17 March 2009 - 08:41 PM

//project name:
//project date:
//your name
//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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1