1 time doing loop, Computer guesses my number)

Jul 26, 2013 at 1:26am
I've been scratching my head at this one and can't figure out how to get the do to be declared. If any one can give me an example on how to get the do to "do it's job" i'll be much appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime> // time liabary

using namespace std;


class Numbergen
{

public:

	char answer;
	
    do {
	theNumber = rand() % 10 + 1; 
	int tries == 0;
	
	
    cout << "I'll try to guess a number between 1 and 10." << endl;
    cin >> number
    cout << "is " << theNumber << " your number?(y/n)" << endl;
    ++tries; 
    if { (answer == number)
cout << "I knew I could do it! It only took me " << tries <<      "times." << endl;
	}
	else {
		cout << "it appears I was wrong, i'll try again... " << endl;
	}
 
    
	} while {(answer != number); }
			


};
	








int _tmain(int argc, _TCHAR* argv[])
{


return 0;
			
}
Last edited on Jul 26, 2013 at 1:32am
Jul 26, 2013 at 1:42am
Not sure if that code will even compile. Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <bits/stdc++.h>
using namespace std;

class Numbergen {
	int theNumber;
public:
	void PlayGame(int tries=0) {
		char answer;
		
		do {
			theNumber = rand() % 10 + 1;
			cout << "I'll  try to guess a number between 1 and 10.\n"
			     << "is " << theNumber << " your number?(y/n) ";
			     ++tries;
			cin >> answer;
			if ( (answer|0x20) == 'y' ) {
				cout << "I knew I could do it! It only took me " << tries << " tries.\n";
			}
			else cout << "it appears I was wrong, i'll try again... " << endl;
		} while ( answer != 'y');
	}

};
	
int main(int argc, char **argv)
{
	(new Numbergen())->PlayGame();
	return 0;
}
Jul 26, 2013 at 1:58am
closed account (Dy7SLyTq)
that wont compile at all

edit: ops, i havent looked at yours smac
Last edited on Jul 26, 2013 at 1:58am
Topic archived. No new replies allowed.