   Simple C++ Game with lots of errors
  Ok, I really haven't had much experience at programming right now and I'm making a text-based C rock, paper, scissors game. So far I have tons of errors. Could somebody help me help out please?Source code:#include <cstdlib>#include <iostream>#include <string>#include <ctime>using namespace std;string rock = "rock";string paper = "paper";string scissor = "scissor";string choice;int comWeapon;int main(int argc, char *argv[]){instructions();fight();system("PAUSE");return 0;}void instructions(){cout << "\tA classic game of rock, paper, scissors.\n\n";}void humanWeapon(){do{cout << "Choose your weapon: ";cin >> choiceif (choice.toupper() == "ROCK")return rock;if (choice.toupper() == "PAPER")return paper;if (choice.toupper() == "SCISSOR")return scissor;} while (choice != "ROCK" && choice != "PAPER" && choice != "SCISSOR");int computerWeapon(){srand(time(0));comWeapon.rand() % 3 1;if (comWeapon == 1)return rock;else if (comWeapon == 2)return paper;else if (comWeapon == 3)return scissor;}void fight(){humanWeapon();computerWeapon();display();if (humanWeapon() == rock && computer == scissor)return humanWins;else if (humanWeapon() == scissor && computer == paper)return humanWins;else if (humanWeapon() == paper && computer == rock)return humanWins;else if (humanWeapon() == rock && computer == paper)return computerWins;else if (humanWeapon() == paper && computer == scissor)return computerWins;else if (humanWeapon() == scissor && computer == rock)return computerWins;}void computerWins(){cout << "\nThe computer wins. Better luck next time!\n\n";}void humanWins(){cout << "\nYou win! Congradulations!\n\n";}display(){cout << "You chose: " << choice << endl;cout << "The computer chose: " << comWeapon << endl;}}[Edited by - Rad94 on September 13, 2007 10:32:58 PM]
  Source code goes in[ source ][ /source ]tags (just leave the spaces out)You would need to post the errors and let us know what lines they occur one if you really want to get quick solutions.   ;Quote:Original post by cshoweSource code goes in[ source ][ /source ]tags (just leave the spaces out)You would need to post the errors and let us know what lines they occur one if you really want to get quick solutions.Ok, I did that.  Most of my errors are something about the functions and the declarations.  There's way too many to list.   ;  OK for one thing you need to prototype ALL of your functions defined after main... main comes along and tries to call instruction(), but since it isn't defined it will be bailing. You need to do something like this :#include <cstdlib>#include <iostream>#include <string>#include <ctime>using namespace std;void instructions();    //Function prototypevoid fight(); //Function prototype...int main(int argc, char *argv[]){ instructions(); fight();  system("PAUSE"); return 0;}void instructions(){ cout << "\tA classic game of rock, paper, scissors.\n\n";}void fight(){ humanWeapon(); computerWeapon(); display(); if (humanWeapon() == rock && computer == scissor)  return humanWins; else if (humanWeapon() == scissor && computer == paper)  return humanWins; else if (humanWeapon() == paper && computer == rock)  return humanWins; else if (humanWeapon() == rock && computer == paper)   return computerWins; else if (humanWeapon() == paper && computer == scissor)  return computerWins; else if (humanWeapon() == scissor && computer == rock)  return computerWins;}...;  Hmm...  Having looked though your code, it appears to me that your main problems probably lie in matching the return type that you are declaring for a given method (as stated before the method name when declaring the method) and what you are actually attempting to return...For example, you declare that the method "humanWeapon" returns nothing ("void humanWeapon()"), but are attempting to return strings from it, it seems.You also seem to have missed the closing brackets for the "humanWeapon" method.Another seeming problem is that you appear to be attempting to return two functions in the "fight" method - not impossible, but not, I daresay, what you intended.By the way, I also noticed that you seem to call srand each time that "computerWeapon" is called - in general, I believe that srand is called but once, at program startup.  (I imagine that the most common exception would be in cases in which one wants to replicate a set of random numbers, and so re-seeds with the original random seed.)   ;  At a quick glance I can tell you that string does not have a toupper method. What you have to do is loop through the contents of the string and change each character individually.Something like:string str = "rock";for(int i = 0; i < str.length(); i++){  str = toupper(str);}To use toupper you need to include the cctype header.You may want to consider using an enum for weapon instead of strings, it'll makes things more straightforward. About the function prototypes - you can do what Capoeirista suggested or you can put your functions above main like so:void instructions(){  cout << "\tA classic game of rock, paper, scissors.\n\n";}//other functions here //they need to be in a certain order//i.e humanWeapon() needs to come before fight() otherwise fight will be//calling a function that it doesn't know about.int main(int argc, char *argv[]){  instructions();  fight();   system("PAUSE");  return 0;}It's entirely upto you which option you prefer but it has been suggested by some that you should only prototype what you really have to and in a small programs like this it's probably better not to.Overall your program isn't too bad, it's nicely broken up into functions, decent variable/function names and is fairly easy to follow.   ;  If you're getting too many errors for you to make sense of, you are trying to write too much at a time. Implement a smaller part first and make it work. (And pay attention; try not to repeat your mistakes in the next part.)   ;  Ok, I tweaked it a bit and I took out the toupper part.#include <cstdlib>#include <iostream>#include <string>#include <ctime>using namespace std;string rock = "rock";string paper = "paper";string scissor = "scissor";string choice;void instructions();string humanWeapon();string computerWeapon();void fight();void computerWins();void humanWins();int comWeapon;void display();int main(int argc, char *argv[]){    srand(time(0));instructions();fight();system("PAUSE");return 0;}void instructions(){cout << "\tA classic game of rock, paper, scissors.\n\n";}string humanWeapon(){do{cout << "Choose your weapon: ";cin >> choiceif (choice == "rock")return rock;if (choice == "paper")return paper;if (choice == "scissor")return scissor;} while (choice != "rock" && choice != "paper" && choice != "scissor");}string computerWeapon(){comWeapon = rand() % 3 + 1;if (comWeapon == 1)return rock;else if (comWeapon == 2)return paper;else if (comWeapon == 3)return scissor;}void fight(){humanWeapon();computerWeapon();display();if (humanWeapon() == rock && computer == scissor)return humanWins;else if (humanWeapon() == scissor && computer == paper)return humanWins;else if (humanWeapon() == paper && computer == rock)return humanWins;else if (humanWeapon() == rock && computer == paper)return computerWins;else if (humanWeapon() == paper && computer == scissor)return computerWins;else if (humanWeapon() == scissor && computer == rock)return computerWins;}void computerWins(){cout << "\nThe computer wins. Better luck next time!\n\n";}void humanWins(){cout << "\nYou win! Congradulations!\n\n";}display(){cout << "You chose: " << choice << endl;cout << "The computer chose: " << comWeapon << endl;}}It says there's something wrong with my if statements for humanWeapon() and there are errors for my return statements in fight().   ;  You're missing a semicolon at the end of the line before your if statements.As for your return statements...1) You declared the function as void fight(). That means that the compiler doesn't expect any return values (hence the void keyword).2) You're trying to return humanWins and computerWins, which don't appear to be valid variable names. Do you mean to be calling the functions by those names? If so, those functions don't return any values either, so returning them wouldn't do anything even if you did fix number 1.You probably want to call the functions humanWins() or computerWins(), then call return.Typically when you start a project like this, you start with an extremely simplified version and add code from there, piece by piece. That way you can tell exactly what caused your errors before you end up with too many to diagnose.   ;  I think your problem is in return humanWins; and return computerWins;firstly, humanWins and computerWins are functions you created, and they should be called with the parentheses like humanWins() or computerWins(). So instead your compiler is looking for variables named humanWins and computerWins, which you never declared in the first place.Secondly you're trying to return functions, which I don't think is allowed cause I think you can only return data types to a function. And even if you could, your fight() function returns a void data type therefore you shouldn't even be returning anything.I think you should try to re-design the whole program though, it doesn't seem to be designed too well and that could cause a lot of unexpected errors to occur later, kinda like how you don't have comWeapon = rand() % 3 + 1; inside your loop which can only mean it will never change values once it's been set. So the computer will end up doing the same thing over and over. 