| | |
guessing game program problem
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 40
Reputation:
Solved Threads: 0
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
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; }
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 Use that before you use rand(); and then just use
here is the link to the Thread on random numbers: http://www.daniweb.com/forums/thread1769.html
C++ Syntax (Toggle Plain Text)
srand((unsigned)time(0))
C++ Syntax (Toggle Plain Text)
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
•
•
Join Date: Oct 2007
Posts: 40
Reputation:
Solved Threads: 0
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; }
•
•
Join Date: Oct 2007
Posts: 40
Reputation:
Solved Threads: 0
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
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
![]() |
Similar Threads
- error in guessing game (Python)
- Number guessing game problem (C++)
- Number Guessing game problem (C++)
- Game of life i/o problem (C++)
- 2D guessing game (Python)
- how will i repeat my whole game program? (Java)
- Applet or Application? (Java)
Other Threads in the C++ Forum
- Previous Thread: Help Me!! New To C++!! Arrays!!
- Next Thread: Displaying a "Hidden Datagrid"
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg simple sorting string strings temperature template text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






