Please help me with my code!

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi I am having trouble getting my code to work. I am using Visual C# 2010 Express and a VisualBasic 10.00.00 reference. I am a beginner and I would like to know what I am doing wrong and how I can fix it.

My homework question:
1. Write a program which prompts the user to enter the age and height in cm. of teenage
boys (ages 13 - 18). The program should compute and print out the average height of the
boys in each category. If the user types ages below 13 or above 18 or a height less than
or equal to zero an appropriate response should be made.

These are the errors I am getting:

1. Invalid token = in class, struct, or interferance member declaration.
2. I nvalid token / in class, struct, or interferance member declaration.
3. nvalid token ; in class, struct, or interferance member declaration.
4. invalid token += in class, struct, or interferance member declaration.
5. Invalid token ( in class, struct, or interferance member declaration.
6. Invalid token { in class, struct, or interferance member declaration.
7. ) expected

I put the code inside a button, and the output should be displayed in a textbox I created which is called TxtBoxDisplay

My Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//declaring variables

//counter
int c13 = 0;
int c14 = 0;
int c15 = 0;
int c16 = 0;
int c17 = 0;
int c18 = 0;

//accumalator
int a13 = 0;
int a14 = 0;
int a15 = 0;
int a16 = 0;
int a17 = 0;
int a18 = 0;

//average
double avg13 = 0;
double a14 = 0;
double a15 = 0;
double a16 = 0;
double a17 = 0;
double a18 = 0;

int age;
int height;

string response;

while (true)
{

response = Microsoft.VisualBasic.Interaction.InputBox("do you wish to continue? y/n","", "", 200, 200);

if (response == "n")
break;

//ask for age and height
age = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("enter your age","","",200, 200);
height = Convert.ToInt32(Microsoft.VisualBasic.Interaction.InputBox("enter your height", "", "", 200, 200);

//dummyproofing
if (age < 13 || age > 18 );
{
MessageBox.Show("ERROR ERROR: INVALID AGE.");
}

else if (height < 0)
{
MessageBox.Show("ERROR, ERROR: INVALID HEIGHT.");
}

//add accumalators and counters
else if (age == 13)
{
c13 = c13 + 1;
a13 = a13 +height;
}

else if (age == 14)
c14 = c14 + 1;
a14 = a14 +height;
}
else if (age == 15)
c14 = c15 + 1;
a14 = a15 +height;
{
else if (age == 16)
c14 = c16 + 1;
a14 = a16 +height;
}
else if (age == 17)
c14 = c17 + 1;
a14 = a17 +height;
{
else if (age == 18)
c14 = c18 + 1;
a14 = a18 +height;
}
}

//Calculating average
avg13 = a13 / c13;
avg14 = a14 / a15;
avg15 = a15 / c15;
avg16 = a16 / c16;
avg17 = a17 / c17;
avg18 = a18 / c18;

//Display average
TxtBoxDisplay.Text += "Final Averages" + Environment.NewLine;
TxtBoxDisplay.Text += "Age" + "/t" + "Average" + Environment.NewLine;
TxtBoxDisplay.Text += "13" + "/t" + avg13.ToString("n2") + Environment.NewLine;
TxtBoxDisplay.Text += "14" + "/t" + avg14.ToString("n2") + Environment.NewLine;
TxtBoxDisplay.Text += "15" + "/t" + avg15.ToString("n2") + Environment.NewLine;
TxtBoxDisplay.Text += "16" + "/t" + avg16.ToString("n2") + Environment.NewLine;
TxtBoxDisplay.Text += "17" + "/t" + avg17.ToString("n2") + Environment.NewLine;
TxtBoxDisplay.Text += "18" + "/t" + avg18.ToString("n2") + Environment.NewLine
}
}



View the full article
 
Back
Top