mardi 27 octobre 2015

Wrong Quiz result

This is the output of the program

I was able to do till to get this result by doing this program below

import java.util.Scanner;

public class aLittleQuiz {

    public static void main(String[] args) {

        // declaring varibles

        String quizStart;
        int quizAns1, quizAns2, quizAns3;

        Scanner input = new Scanner(System.in);

        System.out.println("Are you ready for a quiz? (y / n)");
        quizStart = input.next();

        System.out.println("Okay, here it comes!");

        // quiz answer 1

        System.out.println("\nWhat is the capital of Alaska? \n1) Melbourne\n2) Anchorage\n3) Juneau");
        quizAns1 = input.nextInt();

        if (quizAns1 == 3) {
            System.out.println("That's right");
        } else {
            System.out.println("Your answer is wrong, sorry!");
        }

        // quiz answer 2

        System.out.println("Q2) Can you store the value ''cat'' in a variable of type int? \n1) yes \n2) no");
        quizAns2 = input.nextInt();

        if (quizAns2 == 1) {
            System.out.println("Sorry, ''cat'' is a string. ints can only store numbers.");
        } else if (quizAns2 == 2) {
            System.out.println("Correct!");
        }

        // quiz answer 3

        System.out.println("What is the result of 9+6/3? \n1) 5\n2) 11 \n3) 15/3");
        quizAns3 = input.nextInt();
        if (quizAns3 == 2) {
            System.out.println("That's correct!");
        } else {
            System.out.println("");
        }

        // if (quizAns == 3 && quizAns == ) {

        // }

    }

}

but how I can program this part?

"Overall, you got 2 out of 3 correct. Thanks for playing!"

Aucun commentaire:

Enregistrer un commentaire