|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
Dont know why I am having so much trouble with this program, maybe because I'm pretty new. I bet some of you guys would look at it and just whip it out. I've been trying but I still can't get it! I have a test on this on Saturday, phew, here it goes. Design and develop a program that accepts test score values from the Console window until the user enters the value -1. The value -1 is called a sentinal value, which is used to tell the loop to exit when the number of values is entered. After the user enters the sentinal value (-1), compute the average of values based on the running total and the number of values entered. Display all three values-in the console window using a user-friendly message. For example, test scores of 100, 95, 90, and 90, should produce the results shown in figure 3-19. This is what it should look like when you input it. Enter a score: 100 Enter a score: 95 Enter a score: 80 Enter a score: 90 Enter a score: -1 The total of the values is: 365 The number of scores is: 4 The average is: 91.25 Press the ENTER key to continue._ I can only input two scores right now, and then the program screws up. My variables are Dim intScore As Integer Dim intCount As Integer Dim intAverage As Integer Can someone please solve this, you would be doing me a HUGE favor, Would anyone like to try it? It's supposed to take 10 minutes, but I haven't been able to do it for some reason... I'm not sure whether you're supposed to assign an array or not. My whole class was messed up because of the blizzard and now it's catch up. 
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Sep 2006
Posts: 14,248
Legend
|
Legend
Joined: Sep 2006
Posts: 14,248 |
I don't think you need an array. I would do what it seems like you are doing already. Add the scores in to an overall sum, and then divide by the total number of entries.
Do you have any code snippits we could look at? What error are you getting?
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
Design and develop a program that accepts test score values from the Console window until the user enters the value -1. The value -1 is called a sentinal value, which is used to tell the loop to exit when the number of values is entered. After the user enters the sentinal value (-1), compute the average of values based on the running total and the number of values entered. Display all three values-in the console window using a user-friendly message. For example, test scores of 100, 95, 90, and 90, should produce the results shown in figure 3-19. This is what it should look like when you input it.
Enter a score: 100 Enter a score: 95 Enter a score: 80 Enter a score: 90 Enter a score: -1
The total of the values is: 365 The number of scores is: 4 The average is: 91.25
Press the ENTER key to continue._
I can only input two scores right now, and then the program screws up.
My variables are Dim intScore As Integer Dim intCount As Integer Dim intAverage As Integer
Can someone please solve this, you would be doing me a HUGE favor, Would anyone like to try it? It's supposed to take 10 minutes, but I haven't been able to do it for some reason...
I'm not sure whether you're supposed to assign an array or not. My whole class was messed up because of the blizzard and now it's catch up.
I'll give a little help without doing it for you...
No need for an array as long as you don't have to re-display the individual entries after entering the -1 which is what it looks like to me.
So.... Going by what you show, you need a variable to increment by one for every entry that is not -1 (intCount). You need a variable to temporarily store each score (intScore). You need another variable to keep a running total (intTotal). The average is the running total divided by the incremented variable. Use of a While loop until -1 is entered would help in the solution.
"My signature line goes here."
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
Here is what I've got so far, doesn't work yet. let me see if I can put it correctly on the page. Code:
Module Module1 'program: chapter 3 'programmer: J.Edse 'date: 3-2008 ' description: this program takes in values for test scores and computes them into values, ' a running total, and an average.
Sub Main() Dim intAverage As Decimal Dim intScore As Integer Dim intTotal As Integer Dim intCount As Integer
' Priming read - Accept the inputs Console.Write("Enter a score: ") intScore = Console.ReadLine()
Do While intScore <> -1 Console.Write("Enter a score: ") intScore = Console.ReadLine() If intScore <> -1 Then intCount = intScore + 1 intTotal = intTotal + intScore End If
' Calculate the overall average intAverage = intTotal / intCount
'Write results in console window Console.WriteLine() Console.WriteLine("The total of the values is: " & intTotal) Console.WriteLine("The number of scores is: " & intCount) Console.WriteLine("The average is: " & intAverage) Console.WriteLine() Console.WriteLine("Press the ENTER key to continue.") intScore = Console.ReadLine() Loop
End Sub
End Module
The page messed the spacing up a little, but I don't think it shoud matter. I've been able to get everything this quarter except this problem. 
Last edited by tastybrownies; 03/20/08 06:33 PM.
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
intCount = intScore + 1
Look at this line closely and rethink. You aren't quite there yet.
oh...and watch where you are closing your while loop.
Last edited by I_Rogue; 03/20/08 06:38 PM.
"My signature line goes here."
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Try a little longer before looking at solution below....sorry about the spacing.
Sub Main() Dim intAverage As Decimal Dim intScore As Integer Dim intTotal As Integer Dim intCount As Integer ' Priming read - Accept the inputs intCount = 0 intTotal = 0 intScore = 0 Console.Write("Enter a score: ") intScore = Console.ReadLine() Do While intScore <> -1 intCount = intCount + 1 intTotal = intTotal + intScore Console.Write("Enter a score: ") intScore = Console.ReadLine() Loop ' Calculate the overall average intAverage = intTotal / intCount 'Write results in console window Console.WriteLine() Console.WriteLine("The total of the values is: " & intTotal) Console.WriteLine("The number of scores is: " & intCount) Console.WriteLine("The average is: " & intAverage) Console.WriteLine("Hit a key to end") Console.ReadLine()
End Sub
Last edited by I_Rogue; 03/20/08 07:04 PM.
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
Thank you SO MUCH!!!!!!!!!!!!!!!!!!!!! You are a lifesaver
Now the last thing it wants me to do it when you hit the continue key at the bottom is for the program to start over. If I did do this I would have to make another Do While statement so I could have another Loop at the end?
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Sep 2006
Posts: 28,149 Likes: 833
Legend
|
Legend
Joined: Sep 2006
Posts: 28,149 Likes: 833 |
Uninitialised variables... gotta love em  That and the intCount not being incremented correctly. By the way, can you not do intCount++ or intCount += 1 in VB.NET? If not, I'll stick with C#, thank you 
Browns is the Browns
... there goes Joe Thomas, the best there ever was in this game.
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
I think you can, but I'm still new and am not so experience with it. Thank you for doing that I-Rouge, I can't believe I forgot to assign the variables, wow!
Then again, this is the first time I have used variables that = 0, and they never even taught us how to do that in class.
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
There are a few ways to do that, but yeah....you could put all of it in a Do While.
You would need another variable intContinue as integer and where I ask for the any key to quit, you would ask for something like "Hit 0 to end. 1 to start again." and store it in intContinue.
Initialize intContinue at 1 Do While intContinue = 1 {do everything you already have} Ask to contine or quit Loop
"My signature line goes here."
|
|
|
|
Joined: Sep 2006
Posts: 28,149 Likes: 833
Legend
|
Legend
Joined: Sep 2006
Posts: 28,149 Likes: 833 |
Yeah, I think variables in .NET get instantiated as null, so you gotta at least set strings to "" or ints to 0 before you use them, unless you are declaring them at the same time.... something like that. I've only been playing with .NET for like 3 weeks now, but I've learned a lot of slow painful lessons in creating a wrapper dll for SMO-SQL and a few other things.
Doing intCount++ or intCount += 1 is just short-hand for what you did, but not all languages support it. As an example, InstallScript supports the short-hand for Ints, but requires the other method for strings.... and in C# you can use += for either, but not in C/C++.
Browns is the Browns
... there goes Joe Thomas, the best there ever was in this game.
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
Then again, this is the first time I have used variables that = 0, and they never even taught us how to do that in class.
Wow. I can't believe they didn't teach you to initialize...especially counters. Always initialize....
"My signature line goes here."
|
|
|
|
Joined: Sep 2006
Posts: 14,248
Legend
|
Legend
Joined: Sep 2006
Posts: 14,248 |
Quote:
By the way, can you not do intCount++ or intCount += 1 in VB.NET? If not, I'll stick with C#, thank you
Oh you big programming baby. 
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
Once again thanks for the help, I appreciated it a lot. I finally saw that I was making a moutain out of a mole hill.
So far they've only taught us to declare variables like: Dim intCount As Integer or Dim decAverage As Average
but yeah, no intCount = 0 or intTotal = 0. Maybe they didn't have time, but that's still no excuse. They also said not to worry about arrays yet, although I've done a little bit of them, how are they?
If you don't mind me asking do you program for fun, for a job?
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
Once again thanks for the help, I appreciated it a lot. I finally saw that I was making a moutain out of a mole hill.
So far they've only taught us to declare variables like: Dim intCount As Integer or Dim decAverage As Average
but yeah, no intCount = 0 or intTotal = 0. Maybe they didn't have time, but that's still no excuse. They also said not to worry about arrays yet, although I've done a little bit of them, how are they?
If you don't mind me asking do you program for fun, for a job?
Your welcome for the help.
Arrays are easy to understand and use. They do serve a purpose, but eventually you'll find you need to store values without knowing how many values there are to store. At that point you'll get into data structures like Binary Trees, using Pointers and recursion. That's when things get fun.
I don't program anywhere close to what I once did. I manage now and I farm out my programming....which bumms me out sometimes. I like to program and when I don't use it, I forget syntax of the languages. It gets frustrating when you know what you want to do but can't remember the proper syntax of the language.
"My signature line goes here."
|
|
|
|
Joined: Sep 2006
Posts: 14,248
Legend
|
Legend
Joined: Sep 2006
Posts: 14,248 |
Quote:
I like to program and when I don't use it, I forget syntax of the languages. It gets frustrating when you know what you want to do but can't remember the proper syntax of the language.
LOL ... that's the worst part of programming. It's like trying to learn english, spanish, french, italian and german ... then switching to one for a couple of years, and then moving to another and trying to remember it again. 
Right now I program almost exclusivly in VB, but occasionaly use Perl here and there. When I have to do something in Perl, I'm almost ALWAYS forgetting to put a semi-colon at the end of my statements and can never figure out why they're erroring out.
Of course I usually find my missing semi-colons in the VB code I'm working on concurrently. 
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
What's even worse is when you have to use an older version of VB (VB6) for some legacy apps, VB.net for new apps, and try to also write some Crystal Reports formulas using its Basic syntax that is just different enough to make you scream. So not only is it French, English, Spanish and German....you have to know the "dialects" for all of them too. 
"My signature line goes here."
|
|
|
|
Joined: Sep 2006
Posts: 14,248
Legend
|
Legend
Joined: Sep 2006
Posts: 14,248 |
Then of course someone will invent a NEW language every couple years or so, and everyone will claim that it will replace all other languages, so you learn that too ... and everyone sticks with the old stuff. 
|
|
|
|
Joined: Sep 2006
Posts: 15,015 Likes: 147
Legend
|
Legend
Joined: Sep 2006
Posts: 15,015 Likes: 147 |
Quote:
It gets frustrating when you know what you want to do but can't remember the proper syntax of the language.
It's bad enough that if I don't use a function for a couple months, I need to research it on the internet again to remember the correct syntax. 
I use mostly, .asp here at work now for alot of things, this way anyone can access them from a browser to do what they need. Got a couple of VB programs here as well, but I forgot more than I remember, and can't update them now 
We don't have to agree with each other, to respect each others opinion.
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
It's bad enough that if I don't use a function for a couple months, I need to research it on the internet again to remember the correct syntax. 
I've ridden in that boat quite often and will do so again. 
"My signature line goes here."
|
|
|
|
Joined: Sep 2006
Posts: 28,149 Likes: 833
Legend
|
Legend
Joined: Sep 2006
Posts: 28,149 Likes: 833 |
Damn, I'm glad I'm not the only one with the brain farts you all are describing! I just concluded my first year of programming for a living, and in that year I've had to learn on the fly and use C, C#, VBScript, InstallScript, Perl, PowerBuilder (as well as converting all of my company's apps from PB7 to PB10.5) and some ASP.NET..... it's been enough to almost make me crazy, lol. It does have me wanting to actually take some classes though... I'm finding that while you can self-teach quite a bit, lots of the finer points tend to get lost on you until the precise moment they bite ya in the ass 
Browns is the Browns
... there goes Joe Thomas, the best there ever was in this game.
|
|
|
|
Joined: Sep 2006
Posts: 1,717 Likes: 80
Dawg Talker
|
Dawg Talker
Joined: Sep 2006
Posts: 1,717 Likes: 80 |
Quote:
It gets frustrating when you know what you want to do but can't remember the proper syntax of the language.
It can get really hard - that's why I have tons of manuals and books at work.
I use java, C, perl, Unix shell script, Oracle PL/SQL all the time and it's so easy to confuse the syntax among all the different languages! 
#gmstrong
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
THANK YOU, I just took my CIT final exam and the test was to incorporate a loop into a program. Needless to say I passed with flying colors, and it took me about 2 mintues for the thing to work.
Thanks for helping me out!
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Sep 2006
Posts: 3,044
Hall of Famer
|
Hall of Famer
Joined: Sep 2006
Posts: 3,044 |
congrats!
im pretty good at .Net(Vb and C#) although when it comes to developing applications vb.net is better, it is also better for using unmanaged code and com interop then c# is(ie using stuff outside of the .Net Framework) but c# is superior when it comes to web applications and asp.net and aspx(Active Server Pages)
i usually do my variables as
Dim intcout as integer - nothing
the nothing words instantiates the variable as a "null value" in other words, it just tells it to set aside a block of memory with nothing it it...you can assign a value to it later in your code. This keeps something else from taking that declared memory space, and is more convent then using 0..especially if you have to do type casting or what not.
but since i have begun moving away from Windows and to Linux(only use windows at work because im forced to) i have been using c++ more and more. c++ is much more powerful, and if you get the chance, you should definitely learn it
the advantage of c++ are doesn't require .Net or some other runtime to execute on a machine it is cross-platform portable code executes much faster than .Net or others...minimal overhead
c++ .Net and c++ are 2 different things...c++.net relies on .net, now you can configure visual Studio to do c++ nativly, but you would need the windows sdk along with it which can be downloaded
but make c++ your next learning experience...it is the most powerful language available . I highly reccommened experience in c++ before going to java or c# for the reason that the sytaxes and such of c++ is simliair to java and to an extent c# which means your learning cure for those languages will be much shorter
also, in c++ you have to manage most memory manually, and you will learn and understand alot more about pointers and what not
congrats on passing your exam, i wish you the best of luck in your educational endevours
|
|
|
|
Joined: Sep 2006
Posts: 4,480 Likes: 26
Hall of Famer
|
Hall of Famer
Joined: Sep 2006
Posts: 4,480 Likes: 26 |
Quote:
c++ .Net and c++ are 2 different things...c++.net relies on .net, now you can configure visual Studio to do c++ nativly, but you would need the windows sdk along with it which can be downloaded
I don't recall having to do any special configuration or plug-ins for compiling C or C++ in .NET. Now, maybe if your C++ code uses MFC (which is a BAD idea anyhow) you might need one; don't know.
I personally prefer C# over VB .NET, but I had some Java experience prior to using it so it was a better fit for me, plus it seems to be the language of choice in the .NET arena. VB 6.0 and VB .NET aren't even close in terms of use, so my 6.0 experience didn't help out at all in that area.
I agree that every programmer should have to program in C or C++ and learn about pointers and memory usage. It's nice how .NET and Java help out in this area but it's nice to know how that kind of stuff works. I do a lot of interfacing to point of sale devices, mostly with C++, so memory and pointer understanding is pretty important.
#gmstrong
|
|
|
|
Joined: Jan 2007
Posts: 8,420 Likes: 84
Hall of Famer
|
OP
Hall of Famer
Joined: Jan 2007
Posts: 8,420 Likes: 84 |
Thanks, my college classes I will have to take consist of more VB.NET, JAVA, and C++. I've also heard C++ is one of the most, if not the most used programming language.out there, devloping console games and all sorts of things.
When I read what you wrote about the application building or executing faster, thank god. Sometimes VB.NET takes a really long time and it even manages to freeze my computer quite often.
I'm really excited to learn all of these new things right now.
Find what you love and let it kill you.
-Charles Bukowski
|
|
|
|
Joined: Feb 2007
Posts: 3,405
Hall of Famer
|
Hall of Famer
Joined: Feb 2007
Posts: 3,405 |
Quote:
THANK YOU, I just took my CIT final exam and the test was to incorporate a loop into a program. Needless to say I passed with flying colors, and it took me about 2 mintues for the thing to work.
Thanks for helping me out!
Congrats tasty, glad I could help.
"My signature line goes here."
|
|
|
DawgTalkers.net
Forums DawgTalk Tailgate Forum Anyone pretty good at Visual
Basic.NET ???
|
|