Results 1 to 5 of 5
Thread: IF ELSE program failure.
- 11-12-2011, 01:20 AM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
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;
}
}
}
}
- 11-12-2011, 01:29 AM #2
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: IF ELSE program failure.
= is the assignment operator if you need to compare you need to use the comparison operator ==.
- 11-12-2011, 07:03 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-12-2011, 07:14 AM #4
Senior Member
- Join Date
- Oct 2011
- Posts
- 106
- Rep Power
- 0
Re: IF ELSE program failure.
Your right, but i thought i would address his exact question........every thousand mile journey starts with one step?
- 11-12-2011, 07:48 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,386
- Blog Entries
- 7
- Rep Power
- 17
Re: IF ELSE program failure.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Deployment failure
By Jodokus in forum Java AppletsReplies: 0Last Post: 03-30-2011, 04:58 PM -
Help uninstall! failure
By minty115 in forum New To JavaReplies: 5Last Post: 03-01-2011, 04:07 AM -
Flash Drive Failure
By Sno in forum Forum LobbyReplies: 0Last Post: 08-18-2010, 03:04 PM -
Junit 4. failure(s)
By sonny in forum New To JavaReplies: 4Last Post: 08-03-2010, 04:35 PM -
Animation failure...
By lordbob75 in forum New To JavaReplies: 10Last Post: 05-11-2009, 02:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks