Emergency help

I've been taking a class on scripting that ends today and I can't figure out the last few errors I'm having. The teacher isn't helping either so I came here. I know I should try to figure it out on my own, but I can't and I only have a few hours left.

Here are the errors:

unsigned time;
srand(time(NULL));

gives me this error (2nd line)

1>c:\users\user\documents\visual studio 2010\projects\blah\blah\games.cpp(26): error C2064: term does not evaluate to a function taking 1 arguments

cin >> str;

gives me

1>c:\users\user\documents\visual studio 2010\projects\blah\blah\games.cpp(74): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion)

no other cin has any problems.

It also seems to give me a lot (and I do mean a lot) of errors like this

c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream(466): or 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::operator >>(std::basic_streambuf<_Elem,_Traits> *)'

Can anyone help me for any of these errors? I'm using MVS 2010 if that helps.

Can you post the rest of your code?
Here is the entire code.

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include <string>

using namespace std;




int mentalmath(int);
int guessnumber(int);
int rockpapersissors(int);


int main() {
int answer, winorlose,endgame;
string str;

answer = 0;
winorlose = 0;
endgame = 0;

srand(time(NULL));


while ( !str.compare("NO") ){
cout << "Lets play some games";
cout << "I can play three different games!";
cout << "Mental Math, Guess the Number, and Rock Paper Sissors.";
cout << "Say one for Mental Math, say two for Guess the Number, and say three for Rock, Paper, Sissors";
cin >> answer;

switch (answer) {
case 1:
cout << "Let's play Mental Math!";

winorlose = mentalmath(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
case 2:
cout << "Let's play Guess the Number!";

winorlose = guessnumber(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
case 3:
cout << "Let's play Rock Paper Sissors!";

winorlose = rockpapersissors(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
default:
cout << "That wasn't a choice. Please choose again.";
}


cout << "Would you like to play again? If not say NO";

cin >> str;
}

cout << "Thanks for playing!";


return 0;
}


int mentalmath(int victory)
{
int num1, num2, mathsign, answer, stillright, score = 0;

score = 0;

cout << "How to play: I'll give you a math problem. A simple one"
<< "Just +-*/ and up to 100 for any number"
<< "You play till you get one wrong! Let's get started!";

while (stillright == 0) {
num1 = rand() % 100;
num2 = 1 + rand() % 100;
mathsign = 1 + rand() % 4;
if (mathsign == 1){
cout << num1, "+", num2, "=";
cin >> answer;
if (num1 + num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 2) {
cout << num1, "-", num2, "=";
cin >> answer;
if (num1 - num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 3) {
cout << num1, "*", num2, "=";
cin >> answer;
if (num1 * num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 4) {
cout << num1, "/", num2, "=";
cin >> answer;
if (num1 + num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
}
cout << "Your score was", score;
return 1;
}

int guessnumber(int victory)
{
int num1, answer, score, stillright =0;
int guessesleft = 10;
score = 0;

cout <<"How to play: I will think of a random number between one and 100."
<<"You have 10 guesses to figure out what it is. I will tell you if"
<<"your guess was to high or to low.";
while (stillright == 0) {
num1 = 1 + rand() % 100;
cout << "Alright I have a number. Make a guess.";
while (guessesleft > 0) {
cin >> answer;
if (answer == num1){
cout << "Right!";
score = score + 1;
guessesleft = 10;
break;
}
else if (answer > num1){
cout << "Not quite. Lower.";
guessesleft = guessesleft - 1;
}
else if (answer < num1){
cout << "Not quite. Higher.";
guessesleft = guessesleft - 1;
}
num1 = rand() % 100 ;
cout <<" I have a new number. Make a guess.";
}
stillright = 1;
}
cout << "Out of tries. Your score was", score;
return 1;
}

int rockpapersissors(int victory)
{
int comp, player, pscore, cscore, stillright, matches = 0;

cout <<"How to play: If you don't know how to play rock, paper, sissors, go look it up."
<<"Simply choose 1, 2, or 3, and I will declare who won that round."
<<"1 is rock, 2 is paper, 3 is sissors."
<<"First, how many rounds would you like to play? Please choose an odd number. ";
cin >> matches;
while (matches % 2 == 0) {
cout <<"That was not an odd number. Please try again.";
cin >> matches;
}
cout <<"Alright. Best of ", matches, "matches";
while (matches > 0){
cout <<"What do you choose? Remember 1 = rock 2 = paper 3 = sissors.";
cin >> player;
comp = 1 + rand() % 3;
switch (comp){
case 1:
cout << "I choose Rock";
if (player = 1){
cout << "You chose Rock";
cout << "Tie.";
matches= matches - 1;
}
else if (player = 2){
cout << "You chose paper";
cout << "You win that round.";
pscore = pscore + 1;
matches = matches - 1;
}
else if (player = 3){
cout << "You chose sissors";
cout << "I win.";
cscore = cscore + 1;
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made.";
break;
}
break;
case 2:
cout << "I choose Paper";
if (player = 1){
cout << "You chose Rock";
cout << "I win.";
cscore = cscore + 1;
matches= matches - 1;
}
else if (player = 2){
cout << "You chose paper";
cout << "Tie.";

matches = matches - 1;
}
else if (player = 3){
cout << "You chose sissors";
cout << "You win.";
pscore = pscore + 1;
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made.";
break;
}
break;
case 3:
cout << "I choose Sissors";
if (player = 1){
cout << "You chose Rock";
cout << "You win.";
pscore = pscore + 1;
matches= matches - 1;
}
else if (player = 2){
cout << "You chose paper";
cout << "I win.";
cscore = cscore + 1;
matches = matches - 1;
}
else if (player = 3){
cout << "You chose sissors";
cout << "Tie.";
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made.";
break;
}
break;
}
}

cout << "The game is over.";
if (pscore > cscore){
cout << "You won the game!";
if (cscore = 0)
cout << "You are amazing at this.";
}
if (cscore > pscore){
cout << "You lost the game!";
if (pscore = 0)
cout << "You really suck.";
}
if (cscore = pscore)
cout << "Tie. Good game.";
cout << "You won", pscore, "out of", matches, "matches";
return 1;
}
Last edited on
I see you have an unsigned int named time. Are you using it for anything, and do you have the header <ctime> included so you can use the function time ?

What is str ?

-------------------
Edit: Ah, you've posted code.

Get rid of that unsigned time;

Add the header <ctime>

Add the header <string>

Get rid of #include <string.h>
Last edited on
Alright I made those changes. I'll edit my code post. I'm getting three different errors now, but none or fatal.

1>c:\users\user\documents\visual studio 2010\projects\blah\blah\games.cpp(26): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\user\documents\visual studio 2010\projects\blah\blah\games.cpp(194): warning C4101: 'stillright' : unreferenced local variable
1>c:\users\user\documents\visual studio 2010\projects\blah\blah\games.cpp(94): warning C4700: uninitialized local variable 'stillright' used
When I try to run the program I get this:

'blah.exe': Loaded 'C:\Users\user\Documents\Visual Studio 2010\Projects\blah\Debug\blah.exe', Symbols loaded.
'blah.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'blah.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'blah.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'blah.exe': Loaded 'C:\Program Files\Alwil Software\Avast5\snxhk.dll', Cannot find or open the PDB file
'blah.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'blah.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
The program '[2992] blah.exe: Native' has exited with code 0 (0x0).
See all statements like this? if (player = 2)

That's an assignment. It means: set the value of player to two, and then test it to see if it's false (zero) or true (anything other than zero). Because you just set it to two, it will always come out true.

You probably meant this: if (player == 2)
Right. My bad. Fixed that. The other errors persist.
try this:

while ( str.compare("NO") ){...

Notice there is no '!'.
Alright it's running now, but it's saying I didn't initialize stillright. But I think I did.
In other words, it's still glitching
Had to make some changes. It works now, but debugging is a pain. For some reason I get an infinite loop now in the 2nd game.

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <ctime>
#include <string>

using namespace std;




int mentalmath(int);
int guessnumber(int);
int rockpapersissors(int);


int main() {
int answer, winorlose,endgame;
string str;

answer = 0;
winorlose = 0;
endgame = 0;

srand(time(NULL));


while ( str.compare("NO") ){
cout << "Lets play some games";
cout << "I can play three different games!";
cout << "Mental Math, Guess the Number, and Rock Paper Sissors.";
cout << "Say one for Mental Math, say two for Guess the Number, and say three for Rock, Paper, Sissors ";
cin >> answer;

switch (answer) {
case 1:
cout << "Let's play Mental Math!";

winorlose = mentalmath(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
case 2:
cout << "Let's play Guess the Number!";

winorlose = guessnumber(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
case 3:
cout << "Let's play Rock Paper Sissors!";

winorlose = rockpapersissors(endgame);

if (winorlose == 1)
cout << "You lost!";
else
cout << "You won!";
break;
default:
cout << "That wasn't a choice. Please choose again.";
}


cout << "Would you like to play again? If not say NO";

cin >> str;
}

cout << "Thanks for playing!";


return 0;
}


int mentalmath(int victory)
{
int num1, num2, mathsign, answer, stillright = 0, score = 0;

score = 0;

cout << "How to play: I'll give you a math problem. A simple one"
<< "Just +-*/ and up to 100 for any number"
<< "You play till you get one wrong! Let's get started!";

while (stillright == 0) {
num1 = 1 + rand() % 100;
num2 = 1 + rand() % 100;
mathsign = 1 + rand() % 4;
if (mathsign == 1){
cout << num1;
cout << "+";
cout << num2;
cout << "=";
cin >> answer;
if (num1 + num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 2) {
cout << num1;
cout << "-";
cout << num2;
cout << "=";
cin >> answer;
if (num1 - num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 3) {
cout << num1;
cout << "*" ;
cout << num2;
cout << "=";
cin >> answer;
if (num1 * num2 == answer) {
cout << "Correct!";
score = score + 1;
}
else {
cout << "Wrong";
stillright = 1;
break;
}
}
else if (mathsign == 4) {
cout << num1;
cout << "/";
cout << num2;
cout << "=";
cin >> answer;
if (num1 + num2 == answer) {
cout << "Correct! ";
score = score + 1;
}
else {
cout << "Wrong ";
stillright = 1;
break;
}
}
}
cout << "Your score was ";
cout << score;
return 1;
}

int guessnumber(int victory)
{
int num1, answer, score = 0, stillright =0, right = 0;
int guessesleft = 10;
score = 0;

cout <<"How to play: I will think of a random number between one and 100. "
<<"You have 10 guesses to figure out what it is. I will tell you if "
<<"your guess was to high or to low. ";
while (stillright == 0) {
num1 = 1 + rand() % 100;
cout << "Alright I have a number. Make a guess. ";
while (guessesleft > 0) {
while (right = 0){
cin >> answer;
if (answer == num1){
cout << "Right! ";
score = score + 1;
guessesleft = 10;
right = 1;
break;
}
else if (answer > num1){
cout << "Not quite. Lower. ";
guessesleft = guessesleft - 1;
}
else if (answer < num1){
cout << "Not quite. Higher. ";
guessesleft = guessesleft - 1;
}
}
num1 = rand() % 100 ;
cout <<" I have a new number. Make a guess. ";
right = 0;
}
stillright = 1;
}
cout << "Out of tries. Your score was ", score;
return 1;
}

int rockpapersissors(int victory)
{
int comp, player, pscore = 0, cscore = 0, stillright = 0, matches = 0;

cout <<"How to play: If you don't know how to play rock, paper, sissors, go look it up. "
<<"Simply choose 1, 2, or 3, and I will declare who won that round. "
<<"1 is rock, 2 is paper, 3 is sissors. "
<<"First, how many rounds would you like to play? Please choose an odd number. ";
cin >> matches;
while (matches % 2 == 0) {
cout <<"That was not an odd number. Please try again. ";
cin >> matches;
}
cout <<"Alright. Best of ", matches, "matches ";
while (matches > 0){
cout <<"What do you choose? Remember 1 = rock 2 = paper 3 = sissors. ";
cin >> player;
comp = 1 + rand() % 3;
switch (comp){
case 1:
cout << "I choose Rock ";
if (player == 1){
cout << "You chose Rock ";
cout << "Tie. ";
matches= matches - 1;
}
else if (player == 2){
cout << "You chose paper ";
cout << "You win that round. ";
pscore = pscore + 1;
matches = matches - 1;
}
else if (player == 3){
cout << "You chose sissors ";
cout << "I win. ";
cscore = cscore + 1;
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made. ";
break;
}
break;
case 2:
cout << "I choose Paper ";
if (player == 1){
cout << "You chose Rock ";
cout << "I win. ";
cscore = cscore + 1;
matches= matches - 1;
}
else if (player == 2){
cout << "You chose paper ";
cout << "Tie. ";

matches = matches - 1;
}
else if (player == 3){
cout << "You chose sissors ";
cout << "You win. ";
pscore = pscore + 1;
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made. ";
break;
}
break;
case 3:
cout << "I choose Sissors ";
if (player == 1){
cout << "You chose Rock ";
cout << "You win. ";
pscore = pscore + 1;
matches= matches - 1;
}
else if (player == 2){
cout << "You chose paper ";
cout << "I win. ";
cscore = cscore + 1;
matches = matches - 1;
}
else if (player == 3){
cout << "You chose sissors ";
cout << "Tie. ";
matches = matches -1;
}
else {
cout << "That was not a vaild choice you made. ";
break;
}
break;
}
}

cout << "The game is over. ";
if (pscore > cscore){
cout << "You won the game! ";
if (cscore = 0)
cout << "You are amazing at this. ";
}
if (cscore > pscore){
cout << "You lost the game! ";
if (pscore = 0)
cout << "You really suck. ";
}
if (cscore = pscore)
cout << "Tie. Good game. ";
cout << "You won ", pscore, "out of ", matches, "matches ";
return 1;
}
this

while (right = 0){

should be while (right == 0){. Note the double equals sign. With your code as it is, "right" is assigned zero so therefore the condition will always be false, so that loop is never entered.
Topic archived. No new replies allowed.