• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error help  RSS feed

 
Jacob Sousie
Ranch Hand
Posts: 53
1
Eclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
    I'm trying to find all the errors in this code:



so far I have this:



Can you see any errors I didn't catch?
 
Junilu Lacar
Sheriff
Posts: 11481
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried running that code? What happens when you do? Is it what you expect?

We are happy to help you figure things out but you also have to put in more effort in learning some of these things. That means trying to actually compile and run the code. There's no better experience than first-hand experience when it comes to learning how to program.
 
Jacob Sousie
Ranch Hand
Posts: 53
1
Eclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Have you tried running that code? What happens when you do? Is it what you expect?

We are happy to help you figure things out but you also have to put in more effort in learning some of these things. That means trying to actually compile and run the code. There's no better experience than first-hand experience when it comes to learning how to program.


I have ran the code.  The thing they want (Just found out right now actually) is that they want the loop to count from 1 to 100.  and being new to java I needed a second set of eyes.   I'm still working on it
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A really good rule is to never leave the braces off of blocks like while, do, and if.  Put braces on your while loop and run it.  If it doesn't work, post your new code and what exactly happens or doesn't happen.
 
Jacob Sousie
Ranch Hand
Posts: 53
1
Eclipse IDE Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:A really good rule is to never leave the braces off of blocks like while, do, and if.  Put braces on your while loop and run it.  If it doesn't work, post your new code and what exactly happens or doesn't happen.


I think that fixed it.  Forgetting the {} changed it.  Can't believe I missed it.

This was my task:
While loop counts from 1 to 100
Total (5050) computed correctly






Here's the output:

The sum of the number 1 - 100 is
1
The sum of the number 1 - 100 is
2
The sum of the number 1 - 100 is
3
The sum of the number 1 - 100 is
4
The sum of the number 1 - 100 is
5
The sum of the number 1 - 100 is
6
The sum of the number 1 - 100 is
7
The sum of the number 1 - 100 is
8
The sum of the number 1 - 100 is
9
The sum of the number 1 - 100 is
10
The sum of the number 1 - 100 is
11
The sum of the number 1 - 100 is
12
The sum of the number 1 - 100 is
13
The sum of the number 1 - 100 is
14
The sum of the number 1 - 100 is
15
The sum of the number 1 - 100 is
16
The sum of the number 1 - 100 is
17
The sum of the number 1 - 100 is
18
The sum of the number 1 - 100 is
19
The sum of the number 1 - 100 is
20
The sum of the number 1 - 100 is
21
The sum of the number 1 - 100 is
22
The sum of the number 1 - 100 is
23
The sum of the number 1 - 100 is
24
The sum of the number 1 - 100 is
25
The sum of the number 1 - 100 is
26
The sum of the number 1 - 100 is
27
The sum of the number 1 - 100 is
28
The sum of the number 1 - 100 is
29
The sum of the number 1 - 100 is
30
The sum of the number 1 - 100 is
31
The sum of the number 1 - 100 is
32
The sum of the number 1 - 100 is
33
The sum of the number 1 - 100 is
34
The sum of the number 1 - 100 is
35
The sum of the number 1 - 100 is
36
The sum of the number 1 - 100 is
37
The sum of the number 1 - 100 is
38
The sum of the number 1 - 100 is
39
The sum of the number 1 - 100 is
40
The sum of the number 1 - 100 is
41
The sum of the number 1 - 100 is
42
The sum of the number 1 - 100 is
43
The sum of the number 1 - 100 is
44
The sum of the number 1 - 100 is
45
The sum of the number 1 - 100 is
46
The sum of the number 1 - 100 is
47
The sum of the number 1 - 100 is
48
The sum of the number 1 - 100 is
49
The sum of the number 1 - 100 is
50
The sum of the number 1 - 100 is
51
The sum of the number 1 - 100 is
52
The sum of the number 1 - 100 is
53
The sum of the number 1 - 100 is
54
The sum of the number 1 - 100 is
55
The sum of the number 1 - 100 is
56
The sum of the number 1 - 100 is
57
The sum of the number 1 - 100 is
58
The sum of the number 1 - 100 is
59
The sum of the number 1 - 100 is
60
The sum of the number 1 - 100 is
61
The sum of the number 1 - 100 is
62
The sum of the number 1 - 100 is
63
The sum of the number 1 - 100 is
64
The sum of the number 1 - 100 is
65
The sum of the number 1 - 100 is
66
The sum of the number 1 - 100 is
67
The sum of the number 1 - 100 is
68
The sum of the number 1 - 100 is
69
The sum of the number 1 - 100 is
70
The sum of the number 1 - 100 is
71
The sum of the number 1 - 100 is
72
The sum of the number 1 - 100 is
73
The sum of the number 1 - 100 is
74
The sum of the number 1 - 100 is
75
The sum of the number 1 - 100 is
76
The sum of the number 1 - 100 is
77
The sum of the number 1 - 100 is
78
The sum of the number 1 - 100 is
79
The sum of the number 1 - 100 is
80
The sum of the number 1 - 100 is
81
The sum of the number 1 - 100 is
82
The sum of the number 1 - 100 is
83
The sum of the number 1 - 100 is
84
The sum of the number 1 - 100 is
85
The sum of the number 1 - 100 is
86
The sum of the number 1 - 100 is
87
The sum of the number 1 - 100 is
88
The sum of the number 1 - 100 is
89
The sum of the number 1 - 100 is
90
The sum of the number 1 - 100 is
91
The sum of the number 1 - 100 is
92
The sum of the number 1 - 100 is
93
The sum of the number 1 - 100 is
94
The sum of the number 1 - 100 is
95
The sum of the number 1 - 100 is
96
The sum of the number 1 - 100 is
97
The sum of the number 1 - 100 is
98
The sum of the number 1 - 100 is
99
The sum of the number 1 - 100 is
100
 
Jacob Sousie
Ranch Hand
Posts: 53
1
Eclipse IDE Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:A really good rule is to never leave the braces off of blocks like while, do, and if.  Put braces on your while loop and run it.  If it doesn't work, post your new code and what exactly happens or doesn't happen.


Thanks so much,  I understand how it works now. 
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You lost this line when you refactored:
 
Jacob Sousie
Ranch Hand
Posts: 53
1
Eclipse IDE Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:You lost this line when you refactored:


Does it do anything though?




What's it effecting?
 
Knute Snortum
Sheriff
Posts: 4276
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, it's totaling the count, right?  Isn't the purpose of the program to total the numbers from 1 to 100?
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sousie wrote:. . .Can you see any errors I didn't catch?
The first line contains a serious style error, declaring two variables on the same line. Never mind that the compiler permits it, it is poor style.
The first version of your code also had a serious logic error in line 2, which you have corrected in later editions.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!