• Post Reply Bookmark Topic Watch Topic
  • New Topic

indicated Nmubers before guests  RSS feed

 
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question : Problem i want the output as
1.user Input
2.user Input
3.user Input
and so ON
i need number of Guests
I know this one is wrong but how can i do that .

 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie you told me in one of my post that i should use



instead of

But when i use the first one error pop up or the program doesn't run as i expected
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saad Zahoor wrote:I know this one is wrong but how can i do that .


One recommendation here is to *never* give up on moving forward.

You know it is wrong; so, what is the next step?  Can you figure out why is it wrong? Can you figure out what is causing it to be wrong? And of course, what can you change to get it closer to not being wrong?

Henry
 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me think
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saad Zahoor wrote:Campbell Ritchie you told me in one of my post that i should use . . .
I am quite sure I didn't tell you to use the ; in that line. A correctly‑written loop incorporating such code will work. The ; is incorrect in that location.

Read this. You have to tell us the details of the error you are suffering otherwise we can't help.
 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried every possible way to solve this but in vain .. i give up !
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I simple way of doing it would be to use a counter in this loop:

Declare and initialize a counter outside of the loop, use it to print the guest number, then increment it
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saad Zahoor wrote:I have tried every possible way to solve this but in vain .. i give up !


I don't know why you gave up so easily (seriously, 19 minutes is really quick to give up in vain !!). Quite frankly, you were already headed in the right direction by using the for loop that took an index. The index would have been good to use as the counter.

Like I said, think about why it is wrong?, meaning what is missing?, and think about how to get there. Once you break it down to a counter (that was missing), then you can draw the conclusion that the for loop has an index, that also can be used as a counter.

[EDIT: and apologies for stepping on Knute, who answered minutes before me.]

Henry
 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Help is really Appreciated . Henry Wong , Knute !
Now it is working as i want .




One thing i don't get about the method .Does Every method has its own local variable ? . Can't we access the same variable in multiple variable except for the class variable . I Want to save this info into the file and but can't access the variable

 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple Methods*
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saad Zahoor wrote:Does Every method has its own local variable ?


Not sure what you mean here... You are the coder of your application, and hence, you declare the variables. And if you declare local variables, then it will be local variables...

If you want a variable to be accessed at a larger scope, then you need to declare them as such. This is what instance and static variables are for.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!