#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Making a Rock Paper Scissors in C:Do while loop not working


    I'm teaching myself C and I've tried to make a simple Rock Paper Scissors game but I cant get the do while loop working properly.

    I'm using Visual Studio 2012 as the compiler
    PHP Code:
    #include<stdio.h>
    #include <stdlib.h>
    int check(int aint b);
    int main()
    {
        do
        {
            
    int a;
            
    int b;
            
    char ask;
            
    printf("Player 1 enter\n [1] for rock\n [2] for paper\n [3] for scissors\n");
            
    scanf("%d",&a);
            
    system("cls");
            
    printf("Player 2 enter\n [1] for rock\n [2] for paper\n [3] for scissors\n");
            
    scanf("%d",&b);
            
    system("cls");
            
    check(a,b);
            
    printf("Would you like to Play again?\n\n [y] for yes\n\n [n] for no\n\n ");
            
    scanf("%c",&ask);
        }while(
    ask=='y');
        return 
    0;

    Whenever I try to build the solution it says that "ask" is an undeclared identifier
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,551
    Rep Power
    2337
    You declare ask inside the {} of the do-while loop. The ask variable inside the while() is outside of those braces.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Thank you, fixed that problem now.

IMN logo majestic logo threadwatch logo seochat tools logo