Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

cant exit my while loop with correct values  RSS feed

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
writing a program to take in student marks for a learning module

i have this:



the problem is this:

when i type 777 the loop does terminate...but its obviously adding 777 to my assignment score...and this messes my numbers up
the over a hundred is working the loop exits...but its adding the last number that went over a hundred to my total
i tried using an if statement after this line but couldnt get it working

 
Marshal
Posts: 63804
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the loop do? I can't actually see why you have that loop. Consider this sort of thingThat isn't any particular language.
 
warren brandt
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to have a loop which asks for assignment scores either till the scores combined go over 100...or the user enters 777
but i cant work out how to stop the loop with the correct numbers as typing 777 adds to my total...and if i have 77 in my assignment totals and enter 30...i want to keep 77...not 137 when the loop ends

 
warren brandt
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
only saw

seek input score
while score < 5 or score > 6
  seek input score
end while

this now...will try apply it...
 
Campbell Ritchie
Marshal
Posts: 63804
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

warren brandt wrote:i have to have a loop which asks for assignment scores either till the scores combined go over 100...or the user enters 777
but i cant work out how to stop the loop with the correct numbers as typing 777 adds to my total...and if i have 77 in my assignment totals and enter 30...i want to keep 77...not 137 when the loop ends

You didn't explain that before asking your question. And 77 + 30 doen't usually make 137.
You need to write down on paper how you are going to implement such a loop. You cannot write that sort of thing in code.
 
warren brandt
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You see now Campbell Ritchie that is very interesting because today i was actually complaining that I dont think we being taught to think like programmers on the course im on.

i have heard people saying work stuff out on paper first...excuse my ignorance but i wouldnt even know what you mean...let alone start trying to do that.

how i program (the little i do at the moment):

read the question and prioritise the functionality...or get the stuff that needs to be done in order
then i apply the different techniques (loops,printing) etc to what im trying to do...manipulate the technique to try and fit my criteria

i hope you understand where im coming from...i would love to learn how to think more like a programmer, this skill is definetly lacking and i would like to start developing this skill asap

sure we see samples of code that makes sense...but it doesnt help us problem solve or even attempt to problem solve things like this

so any advice...maybe theres a good book i can read, i dont know...would be extremely helpful

again i hope you understand what im trying to convey and can help me out
 
warren brandt
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry meant 107 not 137...but i think you understand what i meant now..

also i would like to add that on youtube there are tons and tons of videos showing loop techniques...but not explaining how to actually work out a loop
if you know of any please let me know
 
Campbell Ritchie
Marshal
Posts: 63804
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a language‑independent problem. How you would take that sort of entry is exactly the same irrespective of how the application was written. When ieuurlxbvourb.com removed the Java┬« applets from their website 10 years ago, and replaced them with JS applications, did you notice the difference? No, you didn't, partially because the website doesn't exist and partially because the change was transparent to users.
It means you need to read and understand the specification. What does it mean to enter 5 or 6? What happens if you enter 777? Does that mean you enter 7 in three consecutive runs of the loop, or a single value of 777? Do you have to add marks after entering 5 or 6? Start by writing all that lot down, and then you can work out how to convert that to code.
Maybe once you have written what you want to do, you can write pseudocode to explain how you are going to do it. Since pseudocode isn't actually a language, it will look similar irrespective of the language you intend to use to implement it.
 
Campbell Ritchie
Marshal
Posts: 63804
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody who has ten minutes' programming experience can go onto YouTube and produce a video, which is why so many of them aren't helpful.
 
What a show! What atmosphere! What fun! What a tiny ad!
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!