CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Threaded View

  1. #1
    Join Date
    Mar 2012
    Posts
    0

    Help beginner with a simple code.

    Hey there guys I have been practicing C# from a book I purchased and I tried to write up a code today but I am not having much success with it so far so I was hoping you guys could maybe give me some insight on what I need to improve.

    As a short description the program is supposed to calculate the total revenue for tickets sold for a baseball game. Class a tickets are sold for $15, class b 12$ and class C for 9$. The application is supposed to allow the user to enter the number of each class ticket sold and then its supposed to display the income generated for each class of tickets and then a total revenue generated overall.

    I have already made up the UI which contains a bunch of description labels and also text boxes for the user to input the amount of tickets and also labels to display the totals. The code I have so far is:
    Code:
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void calculateRevenueButton_Click(object sender, EventArgs e)
            {
                int classA = 15;  // Creating 4 ints to hold ticket prices
                int classB = 12;
                int classC = 9;
    
                int classAInput;  // Creating 3 ints to hold tickets sold input
                int classBInput;
                int classCInput;
    
                double totalClassA;   // Creating 4 doubles to hold total revenue values
                double totalClassB;
                double totalClassC;
                double totalRevenue;
    
                classAInput = int.Parse(classaTextBox.Text); //Assign int values to classinputs from user input
                classBInput = int.Parse(classbTextBox.Text);
                classCInput = int.Parse(classcTextBox.Text);
    
                totalClassA = classAInput * classA;  // Calculates the total revenues
                totalClassB = classBInput * classB;
                totalClassC = classCInput * classC;
                totalRevenue = totalClassA + totalClassB + totalClassC;
    
                classaRevenueLabel.Text = totalClassA.ToString(); //Displays totals in labels to user
                classbRevenueLabel.Text = totalClassB.ToString();
                classcRevenueLabel.Text = totalClassC.ToString();
                totalRevenueLabel.Text = totalRevenue.ToString();
    It is giving me an error on "classBInput = int.Parse(classbTextBox.Text);" line and saying Input string was not in a correct format.

    If you need any more details of this program let me know and I can list each label name etc and also provide a pic of the UI. (sorry if its confusing)
    Last edited by DataMiser; March 19th, 2012 at 09:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured