Results 1 to 5 of 5
  1. #1
    Domenatrice is offline Member
    Join Date
    Nov 2011
    Posts
    4
    Rep Power
    0

    Default IF ELSE program failure.

    I wrote a program that would help me study for a test and I got 100 errors all were pretaining the if else statements.








    import java.util.*;
    import static java.lang.System.out;

    class test{

    public static void main(String[]args){

    Scanner in = new Scanner(system in);
    Random number = new Random ();

    int question
    int loop
    int times = 0
    int one = 1;

    for (times = 14;){

    one - loop;

    question = Number.nextInt(14) + 1;
    if (question = 1)
    {
    loop ++;
    out.println("what year did the first continental congress meet?");
    int year = in.nextInt();
    if (year = 1774);
    {
    out.println("very nice");
    }
    else if {
    out.println("wrong answer, answer is 1774);
    }
    else (loop = 0) break;
    }
    else if (question = 2)
    {
    loop ++;
    out.println("when were the intolerable acts passed?):
    int year = in.nextInt();
    if (year = 1774)
    {
    out.println("very nice");
    }
    else if {
    out.println("wrong answer answer is 1774");
    }
    else (loop = 0) break;
    }
    else if (question = 3)
    {
    loop ++;
    out.println("what year did the tea party take place?");
    int year = in.nextInt();
    if (year = 1773);
    {
    out.println("very nice");
    }
    else if {
    out.println("wrong, the answer was 1773");
    }
    else (loop = 0) break;
    }
    else if (question = 4)
    {
    loop ++;
    out.println("what year was the boston masacre?");
    int year = in.nextInt();
    if (year = 1770)
    {
    out.println("very nice");
    }
    else if {
    out.println("actually its 1770");
    }
    else (loop = 0) break;
    }
    else if (question = 5)
    {
    loop ++;
    out.println("what year was the townshend act repealed?");
    int year = in.nextInt();
    if (year = 1770)
    {
    out.println("very nice");
    }
    else if{
    out.println("you were so wrong, its 1770");
    }
    else (loop = 0) break;
    }
    else if (question = 6)
    {
    loop ++;
    out.println("what year was the townshend act passed? ");
    int year = in.nextInt();
    if (year = 1767)
    {
    out.println("very nice");
    }
    else if{
    out.println("it is 1767 dont you know");
    }
    else (loop = 0) break;
    }
    else if (question = 7)
    {
    loop ++;
    out.println("what year was the declaratory act passed?");
    int year = in.nextInt();
    if (year = 1766)
    {
    out.println("very nice");
    }
    else if {
    out.println("nope it was 1766, gotcha!");
    }
    else (loop = 0) break;
    }
    else if (question = 8)
    {
    loop ++;
    out.println("what year was the stamp act and the quatering act passed?");
    int year = in.nextInt();
    if (year = 1765)
    {
    out.println("very nice");
    }
    else if {
    out.println("it was 1765 you idiot");
    }
    else (loop = 0) break;
    }
    else if (question = 9)
    {
    loop ++;
    out.println("what year was the quatering act passed?");
    int year = in.nextInt();
    if (year = 1765 )
    {
    out.println("very nice");
    }
    else if {
    out.println("it's 1765, fail!");
    }
    else (loop = 0) break;
    }
    else if (question = 10)
    {
    loop ++;
    out.println("what year were the sons of liberty formed?");
    int year = in.nextInt();
    if (year = 1765);
    {
    out.println("very nice");
    }
    else if {
    out.println("nope its 1765");
    }
    else (loop = 0) break;
    }
    else if (question = 11)
    {
    loop ++;
    out.println("what year was the sugar act passed?");
    int year = in.nextInt();
    if (year = 1764);
    {
    out.println("very nice");
    }
    else if {
    out.println("wow, no it's 1764");
    }
    else (loop = 0) break;
    }
    else if (question = 12)
    {
    loop ++;
    out.println("what year did the french indian war end?");
    int year = in.nextInt();
    if (year = 1763 )
    {
    out.println("very nice");
    }
    else if {
    out.println("it is not that! it is 1763");
    }
    else (loop = 0) break;
    }
    else if (question = 13)
    {
    loop ++;
    out.println("what year was Jamestown founded?");
    int year = in.nextInt();
    if (year = 1607 )
    {
    out.println("very nice");
    }
    else if {
    out.println("I am very sorry it is 1607");
    }
    else (loop = 0) break;
    }
    }
    }
    }

  2. #2
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: IF ELSE program failure.

    = is the assignment operator if you need to compare you need to use the comparison operator ==.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default Re: IF ELSE program failure.

    Yep, comparison for equality cannot be done with a = operator (simple assignment operator); but then again, the code above is so full of errors, I don't even know where to start and I suggest to the OP to throw it away and start again; this stuff is broken beyond repair ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: IF ELSE program failure.

    Your right, but i thought i would address his exact question........every thousand mile journey starts with one step?

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,656
    Blog Entries
    7
    Rep Power
    21

    Default Re: IF ELSE program failure.

    Quote Originally Posted by mwr1976 View Post
    Your right, but i thought i would address his exact question........every thousand mile journey starts with one step?
    True, but in this case I still suggest the OP to take one step back and start again (and read a tutorial first), the shown code is nothing but a mess.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Deployment failure
    By Jodokus in forum Java Applets
    Replies: 0
    Last Post: 03-30-2011, 04:58 PM
  2. Help uninstall! failure
    By minty115 in forum New To Java
    Replies: 5
    Last Post: 03-01-2011, 04:07 AM
  3. Flash Drive Failure
    By Sno in forum Forum Lobby
    Replies: 0
    Last Post: 08-18-2010, 03:04 PM
  4. Junit 4. failure(s)
    By sonny in forum New To Java
    Replies: 4
    Last Post: 08-03-2010, 04:35 PM
  5. Animation failure...
    By lordbob75 in forum New To Java
    Replies: 10
    Last Post: 05-11-2009, 02:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •