Rock Paper Scissors Program Help

This is a discussion on Rock Paper Scissors Program Help within the C Programming forums, part of the General Programming Boards category; Hey all, I just typed up a program for rock paper scissors that I need to turn in and print ...

  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 :-(
    Attached Files Attached Files
    Last edited by Sep1256; 11-23-2010 at 12:09 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,415
    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'.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,415
    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().
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    21,415
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,162
    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, 06:14 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21