Thread: Rock Paper Scissors Program Help

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    4

    Rock Paper Scissors Program Help

    Hey all,
    I just typed up a program for rock paper scissors that I need to turn in and print to a .txt file. Unfortunately when I ran it, I'm receiving 30+ errors that really are either "undeclared identifiers", "illegal operands", or "syntax errors". Also, I'm having trouble converting a character into an integer to return to my main function so that I can run my if-statement.... If you can give any help, I'd be much obliged.


    Note: I'm not that lingo-savvy or computer programming literate so please, go easy :-(
    Last edited by Sep1256; 11-23-2010 at 01:09 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If you want specific help, you should post the program's source code (in [code][/code] bbcode tags). Otherwise, you have two general options: fix the errors one by one; or redo from scratch, but compile the program as you write it part by part, and thereby be able to fix the errors as you write them.

    Quote Originally Posted by Sep1256
    I'm having trouble converting a character into an integer
    I am not entirely sure what you want here, but my guess is that you just need to subtract '0'.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Thanks laserlight. I edited my first post

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This statement has a syntax error:
    Code:
    charactermove=char;
    what were you trying to do by writing it?

    This statement is incomplete:
    Code:
    scanf("%c");
    You should provide a second argument with the address of the char to read in. Actually, it may be simpler to just use getchar().
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    The first one "charactermove" was created after the function error said that I didn't have anything to return....initially, I had return int char....and that was extremely wrong. So, I created a variable to see if it'll return that [charactermove] instead. I just want the character the user enters to return as the assigned integer so that I can use my if statement to compare....

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Sep1256
    So, I created a variable to see if it'll return that [charactermove] instead.
    Ah, so the syntax really should be:
    Code:
    char charactermove;
    Quote Originally Posted by Sep1256
    I just want the character the user enters to return as the assigned integer so that I can use my if statement to compare....
    Why not compare characters instead?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Why not compare characters instead?

    Would this make sense? Like I've said...I'm not that good at this ...

    Code:
    int player_move (char c)
    {
    
    	
    	printf(	"Make your move...\n"
    		"Input p, r, or s: \n");
    	scanf("%c");
    
    	if(char = 'r' || 'R')
    	{
    	return 1;
    	else if(char = 'p' || 'P')
    	{
    	return 2;
    	}
    	else if(char = 's' || 'S')
    	{
    	return 3;
    	}
    	}
    
    }

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You still need to pass the address of a variable to scanf() to store the character in. Here's an example of how scanf() should be used:
    Code:
    char ch;
    scanf("%c", &ch);
    if(ch == 'w' || ch == 'W') // Alternatively - if(toupper(ch) == 'W') or if(tolower(ch) == 'w'), but definitely not if(ch == 'w' || 'W')
      puts("You're a winner!");
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  2. Rock, Paper, Scissors
    By Slynet in forum C Programming
    Replies: 2
    Last Post: 02-13-2009, 07:14 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Replies: 5
    Last Post: 09-03-2001, 09:45 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM