Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Quick Visual Basic help please?
New Posts  All Forums:Forum Nav:

Quick Visual Basic help please?

post #1 of 6
Thread Starter 
Ok here is a practice exam question but i can't seem to get the code to operate as it should.
Quote:
NoOfGamesInMatch Integer Stores the number of games in the match (speciÞ ed by
user)
NoOfGamesPlayed Integer Stores the number of games played so far
PlayerOneScore Integer Stores the number of games won by Player One
PlayerTwoScore Integer Stores the number of games won by Player Two
PlayerOneWinsGame Char Stores a ’Y’ if Player One won the game and ’N’
otherwise
Turn over!
7
M/Jun10/COMP1
Figure 4
PlayerOneScore " 0
PlayerTwoScore " 0
OUTPUT "How many games?"
INPUT NoOfGamesInMatch
FOR NoOfGamesPlayed " 1 TO NoOfGamesInMatch Do
OUTPUT "Did Player One win the game (enter Y or N)?"
INPUT PlayerOneWinsGame
IF PlayerOneWinsGame = ’Y’
THEN PlayerOneScore " PlayerOneScore + 1
ELSE PlayerTwoScore " PlayerTwoScore + 1
ENDIF
ENDFOR
OUTPUT PlayerOneScore
OUTPUT PlayerTwoScore
What you need to do
Write a program for the above algorithm.
Test the program by showing the results of a match consisting of three games where
Player One wins the Þ rst game and Player Two wins the second and third games


Here is my program
Quote:
Module Module1
Dim NoOfGamesInMatch As Integer
Dim NoOfGamesPlayed As Integer
Dim PlayerOneScore As Integer
Dim PlayerTwoScore As Integer
Dim PlayerOneWinsGame As Char

Sub Main()
PlayerOneScore = 0
PlayerTwoScore = 0
Console.WriteLine("How many games?")
NoOfGamesInMatch = Console.ReadLine
NoOfGamesPlayed = 1 > NoOfGamesInMatch 'Check
Console.WriteLine("Did Player One win the game (enter Y or N)?")
PlayerOneWinsGame = Console.ReadLine
PlayerOneWinsGame = ("Y") ' Check
PlayerOneScore = PlayerOneScore + 1
PlayerTwoScore = PlayerTwoScore + 1
PlayerOneScore = Console.ReadLine
PlayerTwoScore = Console.ReadLine
End Sub
End Module
Please help!
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #2 of 6
Thread Starter 
I've checked the mark scheme. Just got 1 or 2 minor things wrong.
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #3 of 6
No, the entire thing is wrong. I don't see any loops or If/Else statements. And then you're setting PlayerOneWinsGame to user input and then immediately setting it to "Y." And near the end, you're setting the scores instead of outputting them.

So, you should probably go back and start with the basics and learn how to program, especially if you're trying to get something out of it. If you want to be a programmer, then don't start your learning by asking people how to fix your code. Try to learn, and then when you have specific problems, post why you think it should work, why you think it might not, and any error messages. But your code is just way off. If you're taking a class for some unrelated major, then yes, you should still learn the basics.

The basics really aren't that hard.
Main System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X6 1090T MSI 890FXA-GD70 XFX Radeon 5850 16 GB Corsair XMS3 DDR3 1333 
Hard DriveOSMonitorPower
3 X 7200 RPM / 1 TB Win 7 Ultimate 64 2 x ASUS 23" VH232H 1080P SeaSonic X-650 
Case
Corsair 600T 
  hide details  
Reply
Main System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X6 1090T MSI 890FXA-GD70 XFX Radeon 5850 16 GB Corsair XMS3 DDR3 1333 
Hard DriveOSMonitorPower
3 X 7200 RPM / 1 TB Win 7 Ultimate 64 2 x ASUS 23" VH232H 1080P SeaSonic X-650 
Case
Corsair 600T 
  hide details  
Reply
post #4 of 6
Thread Starter 
As i said, checked the mark scheme and only got 2 things wrong, so that is 7 out of 9 marks. The rest of my code is identical. It works perfectly fine now.
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
post #5 of 6
No, you're wrong. Your program is wrong in more than two ways. As I said above, you need to understand the concepts. If you change those two lines with the 'Check comment, your program will still be wrong. If you want to know what your program does in laymen's terms, here is what it does. If you ask actual programmers for programming advice, don't you think they'd actually give you advice on how to make it right? It's kind of hard to give advice on how to change something but still make it incorrect



1. Create Integer called NoOfGamesInMatch
2. Create Integer NoOfGamesPlayed
3. Create Integer PlayerOneScore
4. Create Integer PlayerTwoScore
5. Create Integer PlayerOneWinsGame
6. Computer sets PlayerOneScore to 0
7. Computer sets PlayerTwoScore to 0
8. Computer asks "How many games?"
9. User types in a response
10. Computer stores the response in NoOfGamesInMatch. If the response cannot be cast to Integer, program crashes.
11. Computer tests to see that the expression (NoOfGamesPlayer = 1), which evaluates to Boolean of False is greater than NoOfGamesInMatch.
12. Computer asks "Did Player One win the game (enter Y or N)?"
13. User types in a response
14. Computer stores the response in PlayerOneWinsGame. If the response cannot be cast to Integer, program crashes.
15. Despite the fact that the computer allowed the user to tell it what to set for PlayerOneWinsGame, computer overrides the response and sets PlayerOneWinsGame to "Y".
16. Computer adds 1 to PlayerOneScore, regardless of who won
17. Computer adds 1 to PlayerTwoScore, regardless of who won
18. Computer sets PlayerOneScore to whatever the user types, crashing if needed.
19. Computer sets PlayerTwoScore to whatever the user types, crashing if needed.
20. Program ends
Main System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X6 1090T MSI 890FXA-GD70 XFX Radeon 5850 16 GB Corsair XMS3 DDR3 1333 
Hard DriveOSMonitorPower
3 X 7200 RPM / 1 TB Win 7 Ultimate 64 2 x ASUS 23" VH232H 1080P SeaSonic X-650 
Case
Corsair 600T 
  hide details  
Reply
Main System
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X6 1090T MSI 890FXA-GD70 XFX Radeon 5850 16 GB Corsair XMS3 DDR3 1333 
Hard DriveOSMonitorPower
3 X 7200 RPM / 1 TB Win 7 Ultimate 64 2 x ASUS 23" VH232H 1080P SeaSonic X-650 
Case
Corsair 600T 
  hide details  
Reply
post #6 of 6
Thread Starter 
Quote:
Originally Posted by tand1 View Post
No, you're wrong. Your program is wrong in more than two ways. As I said above, you need to understand the concepts. If you change those two lines with the 'Check comment, your program will still be wrong. If you want to know what your program does in laymen's terms, here is what it does. If you ask actual programmers for programming advice, don't you think they'd actually give you advice on how to make it right? It's kind of hard to give advice on how to change something but still make it incorrect



1. Create Integer called NoOfGamesInMatch
2. Create Integer NoOfGamesPlayed
3. Create Integer PlayerOneScore
4. Create Integer PlayerTwoScore
5. Create Integer PlayerOneWinsGame
6. Computer sets PlayerOneScore to 0
7. Computer sets PlayerTwoScore to 0
8. Computer asks "How many games?"
9. User types in a response
10. Computer stores the response in NoOfGamesInMatch. If the response cannot be cast to Integer, program crashes.
11. Computer tests to see that the expression (NoOfGamesPlayer = 1), which evaluates to Boolean of False is greater than NoOfGamesInMatch.
12. Computer asks "Did Player One win the game (enter Y or N)?"
13. User types in a response
14. Computer stores the response in PlayerOneWinsGame. If the response cannot be cast to Integer, program crashes.
15. Despite the fact that the computer allowed the user to tell it what to set for PlayerOneWinsGame, computer overrides the response and sets PlayerOneWinsGame to "Y".
16. Computer adds 1 to PlayerOneScore, regardless of who won
17. Computer adds 1 to PlayerTwoScore, regardless of who won
18. Computer sets PlayerOneScore to whatever the user types, crashing if needed.
19. Computer sets PlayerTwoScore to whatever the user types, crashing if needed.
20. Program ends
rep, cheers for that. Had my test today. I did the program. It was much eisier than this. You just had to make an array of 4 names then search for one of those names to bring up some information. I written and tested it in the exam and it worked exactly how it should. Like i said, it was much more easy than the one i posted on here. Thanks for the info anyway mate.
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
X79-GCN
(22 items)
 
  
CPUMotherboardGraphicsRAM
Intel 3930K 4.5GHz HT GIGABYTE GA-X79-UP4 AMD R9-290X GEil Evo Potenza DDR3 2400MHz CL10 (4x4GB) 
Hard DriveCoolingCoolingCooling
Samsung 840 Pro 120GB EK Supremacy (CPU) NF F12's P/P (360 Rad)  NF A14's (420 Rad)  
CoolingCoolingCoolingCooling
XSPC Chrome Compression Fittings EK RES X3 150 Primochill PremoFlex Advanced LRT Clear 1/2 ID EK-FC (R9 290X) 
CoolingCoolingCoolingOS
EK D5 Vario Top-X  Phobya G-Changer V2 360mm Phobya G-Changer V2 420mm Win 10 x64 Pro 
MonitorKeyboardPowerCase
BenQ XR3501 35" Curved Corsair Vengeance K90 Seasonic X-1250 Gold (v2) Corsair 900D 
MouseAudio
Logitech G400s Senn HD 598 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Quick Visual Basic help please?