Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

tell me why this is not working

java

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 27 December 2015 - 06:05 PM

hi all

am doing this multiple choice game and have been trying to implement a number amount of chances the user has to entered the correct answer before the game end.

 

i would like to know why this code is not working. the compiler is not reading it at all 

 

here is the code:

  
        
        System.out.println("******************welcome to round 1************************");
        
        System.out.println("Hi what is your name");
        playername = userinput.next();
        System.out.println(playername+" you have a very unique name, my dearest");
        System.out.println(playername+" how old are you");
        playerage = userinput.nextInt();
        //initializing the player name and age
        
         // this is checking to see wjther the player entered the correct age
        if(playerage < 8 || playerage > 13)
        {
            System.out.println(playername+" you have entered an invalid age");
            System.exit(0);//this indicating that the player has entered the wrong age, so the game exit
        }
        else
        {
            System.out.println(playername+" come let's play");
            //this is statinf that the player entered the correct age
        }
        
           i=1;
           while(i<=4)
           {
               //get the random numbers
               rand = 1 + randobj.nextInt(25);
               rand2 = 1 + randobj.nextInt(8);
               correctans = rand + rand2;
               incorrectans = 25 + randobj.nextInt(50);
               
               System.out.println(playername+" round 1 "+ " level "+ i + " question "+ i + " you are requred to match the letter with the correspnding answer");
               System.out.println(playername+" please add "+ rand + " + "+ rand2);
               
               System.out.println("A:"+correctans);
               System.out.println("B:"+incorrectans);
               choice = userinput.next().charAt(0);
               
               if(choice == 'a')
               {
                   System.out.println(playername+" wow, well done kiddo, correct is right, you did well");
                   score += score + 650;
                   System.out.println("round 1 ");
                   System.out.println("level "+ i);
                   totalscore += score;
                   System.out.println("the total score is "+ totalscore);
                   i++;
               }
               else if(choice =='b')
               {
                   System.out.println(playername+" no this is not the correct answer, you need to buck up, try again");
                   score -= score - 225;
                   System.out.println("round 1");
                   System.out.println("level "+ i);
                   totalscore -= score;
                   System.out.println("the total score is "+totalscore );
                   i++;
               }
               
                int chancesRemaining = 0;
                
                while(chancesRemaining !=0 && i <=4)
               {
                   if(chancesRemaining ==0)
                   {
                       if(chancesRemaining == 4)
                       {
                           System.out.println(playername+"okay you have %d tries left "+ chancesRemaining);
                       }
                       else if(chancesRemaining == 3)
                       {
                           System.out.println(playername+"\n you can do it you hve %d tries "+chancesRemaining); 
                       }
                       else if(chancesRemaining == 2)
                       {
                           System.out.println(playername+"\ncome on now %d tries left, you can do it "+ chancesRemaining);
                       }
                       else if(chancesRemaining == 1)
                       {
                           System.out.println(playername+"\n you can more than do, %d tries left "+ chancesRemaining);
                       }
                       
                   }
               }

any help would be greatly appreciated as soon as possible 



#2 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts

Posted 15 January 2016 - 08:29 AM

What is the compiler's message when you attempt to compile this program?

 

I'm also gonna assume that you've only given us what's between the typical:

public class ... {
    public static void main(String[] args) ...

?



#3 divinity03

divinity03

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 16 January 2016 - 01:41 PM

hi lethalwire

 

just want to let you kno that I have since change around the whole code and i have pass tht assignment, didnt pass the whole course and thanks anyway, will be doing another one and will come back here for help