Help with this code, I have to do a cafeteria survey with 20 students, see code and errors I get, thanks

Dim studentRate(20) As Integer
Dim counter As Integer
Dim starCounter As Integer
Dim frequencies(20) As String
Dim phrase As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
counter = 0
phrase = "Rating" & vbTab & "Frequencies" & vbCrLf
TextBox1.Text = phrase
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text = "" Then
MsgBox("select rating...")
Else
counter += 1
If counter > 20 Then
MsgBox("all students have rated the food...")
Else
'register student rating
studentRate(counter) = ComboBox1.Text
phrase &= counter & vbTab
'write number of stars
For starCounter = 1 To studentRate(counter)
phrase &= "*"
Next
phrase &= vbCrLf
TextBox1.Text = phrase
If counter > 20 Then
MsgBox("all students have rated the food...")
End If
End If
End If
End Sub
End Class

These are the errors;

1>------ Build started: Project: CafeteriaSurvey, Configuration: Debug Win32 ------
1>Compiling...
1>CafeteriaSurvey.cpp
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(2) : error C2146: syntax error : missing ';' before identifier 'studentRate'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(2) : error C2146: syntax error : missing ';' before identifier 'As'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C2146: syntax error : missing ';' before identifier 'Integer'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C2146: syntax error : missing ';' before identifier 'Dim'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C2146: syntax error : missing ';' before identifier 'counter'
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\pdmmonte\desktop\simplycpp\tutorial13\exercises\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey\cafeteriasurvey.cpp(3) : error C2086: 'int Dim' : redefinition

You appear to be writing your code in Visual Basic, but then you're trying to compile is as if it were C++. They're two different languages - a C++ compiler will not be able to turn your Visual Basic code into a program.

I thought I could open here at work, but I guess not, thanks for your input.

Could you help me to get started with this code;

Twenty students were asked to rate, on a scale of 1-10, the quality of food in the school cafeteria, with 1 being "awful" and 10 being "excellent". Your application should present the user with a menu of options. Place the twenty responses into an int array and determine the frequency of each rating. Display the frequencies as a histogram. Recall that a histogram (also known as a bar chart) is a chart where numeric values are displayed as bars. In such a chart, longer bars represent larger numeric values. One simple way to display numeric data graphically is with a histogram that shows each value as a bar of asterisks. Figure 13.31 in your text demonstrates the completed application.

I am not sure where to begin!!

Begin by making an array of int big enough to fit every answer, and then have a loop run 20 times to get each value, and put each value into the array.

This article has been dead for over six months. Start a new discussion instead.