guessing game program problem

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

guessing game program problem

 
0
  #1
Nov 12th, 2007
i have been fooiling around with my program for class trying to get it to work, but now i get this error message:
error C2064: term does not evaluate to a function taking 1 arguments
it is referring to this part of the program:
num = (rand() + time(0)) % 1000;
could anyone explain what i did wrong and how i can fix it. thank you
here is the program. i have been having problems doing this correctly so i hope this works

  
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main ()
{
	int num;
	int guess;
	bool done;
	int noOfGuesses=0;
	int ncount;
	int sum=0;
	int noofgamesplayed;
	int avgNoOfGuesses;
	int time;

	 sum += noOfGuesses;
	 avgNoOfGuesses=sum/noofgamesplayed;

	num = (rand() + time(0)) % 1000;
	done = false;
	while ((noOfGuesses < 10) && (!done))
	
	{
		cout << "Enter an integer greater"
			<< " than or equal to 0 and "
			<< "less than 1000: ";
		cin >> guess;
		cout << endl;
		noOfGuesses++;
		if (guess == num)
		{
			cout << "you guessed the correct "
				<< "number." << endl;
			done = true;
		}
		else
			if (guess < num)
				cout << "Your guess is lower "
				<< "than the number. \n"
				<< "Guess again!" << endl;
			else
				cout << "Your guess is higher "
				<< "than the number.\n"
				<< "guess again!" << endl;
			cout <<"Total gueses equal " << noOfGuesses << endl;


		
	}
	return 0;
	}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 47
Reputation: joshua.tilson is an unknown quantity at this point 
Solved Threads: 0
joshua.tilson's Avatar
joshua.tilson joshua.tilson is offline Offline
Light Poster

Re: guessing game program problem

 
1
  #2
Nov 12th, 2007
It looks like you have a couple of things mixed up. There was just a great thread on using random numbers. before you use rand() you will want to seed the generator with a random variable first. That is done by using
  1. srand((unsigned)time(0))
Use that before you use rand(); and then just use
  1. rand() % 1000;

here is the link to the Thread on random numbers: http://www.daniweb.com/forums/thread1769.html
Last edited by joshua.tilson; Nov 12th, 2007 at 4:14 pm. Reason: Added thread Link
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: guessing game program problem

 
0
  #3
Nov 12th, 2007
i put it in but i don't know if i did it correctly. now i have a an error that says:
error C2064: term does not evaluate to a function taking 1 arguments. it is talking about this line:
srand((unsigned)time(0))
what did i do wrong? please let me know if you can
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 10
Reputation: hgedek is an unknown quantity at this point 
Solved Threads: 1
hgedek's Avatar
hgedek hgedek is offline Offline
Newbie Poster

Re: guessing game program problem

 
1
  #4
Nov 12th, 2007
delete int time then use srand((unsigned)time(0))
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: guessing game program problem

 
0
  #5
Nov 12th, 2007
thanks, i fixed that, now i have a debug error which says that the variable 'noofgamesplayed' is being used without being defined. how can i fix that. i am so confused
thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: guessing game program problem

 
1
  #6
Nov 13th, 2007
> int noofgamesplayed;
noofgamesplayed++; Is using it without it being defined.
cout << "You played " << noofgamesplayed << " games"; Is also using it without it being defined.

int noofgamesplayed = 0; Now we're cooking!.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: guessing game program problem

 
0
  #7
Nov 13th, 2007
thank you for your help. i really appreciate it
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

guessing game problems AAAAUUUGGHHH

 
0
  #8
Nov 13th, 2007
i have been working on this program for the last month and it is driving me nuts. i have been listening to all the advice you guys have been giving me and somehow i keep getting a debug error. could someone pleeeeaaasssseee look over what i have and tell me how or what i have to fix. the program should ask (at the end of the guesses or when they get the answer) if they want to play again and react accordingly. it should also display some summary information including number of games played, number of correct guesses and average number of guesses it took to get the right answer. i really need this project to work. it is for half my grade. any help would be greatly appreciated. here is what i have.

  
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main ()
{
	int num;
	int guess;
	bool done;
	int noOfGuesses=0;
	int ncount;
	int sum=0;
	int noofgamesplayed;
	int avgNoOfGuesses; 
	noofgamesplayed++;

	

 sum += noOfGuesses;
	 avgNoOfGuesses=sum/noofgamesplayed;
	srand((unsigned)time(0))
	;num = (rand() % 1000);
	done = false;
	while ((noOfGuesses < 10) && (!done))
	
	{
		cout << "Enter an integer greater"
			<< " than or equal to 0 and "
			<< "less than 1000: ";
		cin >> guess;
		cout << endl;
		noOfGuesses++;
		if (guess == num)
		{
			cout << "you guessed the correct "
				<< "number." << endl;
			done = true;
		}
		else
			if (guess < num)
				cout << "Your guess is lower "
				<< "than the number. \n"
				<< "Guess again!" << endl;
			else
				cout << "Your guess is higher "
				<< "than the number.\n"
				<< "guess again!" << endl;
			cout <<"Total gueses equal " << noOfGuesses << endl;
			cout << "you played " << noofgamesplayed << " games";


		
	}
	return 0;
	}
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 54
Reputation: tracethepath is an unknown quantity at this point 
Solved Threads: 4
tracethepath's Avatar
tracethepath tracethepath is offline Offline
Junior Poster in Training

Re: guessing game problems AAAAUUUGGHHH

 
0
  #9
Nov 13th, 2007
where are you facing the problem...???
With Regards...
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: guessing game problems AAAAUUUGGHHH

 
0
  #10
Nov 13th, 2007
when i go to debug it gives me a warning:
run time check #3: the variable 'noofgamesplayed' is being used without being defined. i have been getting this message constantly. also when i build the solution, i get 2 warnings:
warning C4101: 'ncount' : unreferenced local variable
and
warning C4700: uninitialized local variable 'noofgamesplayed' used
I am at my wits end. any help is appreciated
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC