Link to home
Start Free TrialLog in
Avatar of rtod2
rtod2Flag for United States of America

asked on

Correct space and add $ sign

The code below produces the form shown here >> http://screencast.com/t/w0CP7X9kE6 after the Calculate Revenue button is pressed.  I like how the information is being displayed with a couple of exceptions.  I'd like to add a $ sign in the Total Revenue Generated area and add a space between the $ sign and the amount for each item above it.  I need to know how to change the attached code and on what line to make the change.  Assistance is greatly appreciated.

/* 304_PennerT_Lab03
Ted R Penner
000305507
Self-Paced, Per prior discussion with instuctor.
Oct 12, 2011
Purpose: To calculate revenue from stadium ticket sales.*/

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 _304_PennerT_Lab03
{
    public partial class stadiumSeatingForm : Form
    {
        public stadiumSeatingForm()
        {
            InitializeComponent();
        }
        private void calculateRevenueButton_Click_1(object sender, EventArgs e)
        {
            try
            {
                // Declare Named Constants

                    const decimal CLASS_A_SEATS = 15.00m; const decimal CLASS_B_SEATS = 12.00m; const decimal CLASS_C_SEATS = 9.00m;

                // Declare Varialbles

                    decimal classATickets; decimal classBTickets; decimal classCTickets;
                    decimal classARevenue; decimal classBRevenue; decimal classCRevenue;
                    decimal totalRevenue;

                // Convert Text Box Values (which are string values) to the appropriate data type using a Parse method and assign to related variable.

                classATickets = decimal.Parse(classATicketsSalesBox.Text); classBTickets = decimal.Parse(classBTicketsSalesBox.Text); classCTickets = decimal.Parse(classCTicketsSalesBox.Text);

                // Process Calculations

                    classARevenue = classATickets * CLASS_A_SEATS; classBRevenue = classBTickets * CLASS_B_SEATS; classCRevenue = classCTickets * CLASS_C_SEATS;
                    totalRevenue = classARevenue + classBRevenue + classCRevenue;

                // Display Numeric Output to appropriate control by converting the numeric value to a string using the ToString method.

                    classARevenueBox.Text = classARevenue.ToString("c"); classBRevenueBox.Text = classBRevenue.ToString("c"); classCRevenueBox.Text = classCRevenue.ToString("c");
                    totalRevenueBox.Text = totalRevenue.ToString();
            }
            catch (Exception ex)
            {
                // Display the deault error message.
                
                    MessageBox.Show(ex.Message);
            }
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            // Clear form and set focus
               
                classATicketsSalesBox.Text = " "; classBTicketsSalesBox.Text = " "; classCTicketsSalesBox.Text = " ";
                classARevenueBox.Text = " "; classBRevenueBox.Text = " "; classCRevenueBox.Text = " ";
                totalRevenueBox.Text = " ";
        }
        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close application
                
                this.Close();
        }
    }
}

Open in new window

Avatar of johnsone
johnsone
Flag of United States of America image

Couldn't you change this:

totalRevenueBox.Text = totalRevenue.ToString();

to this:

totalRevenueBox.Text = "$ " + totalRevenue.ToString();
Avatar of KBerger
KBerger

Hi,

Wouldn't totalRevenue.Text=totalRevenue.ToString("c") do the Trick?
This is how all Otter bxes are Vormärzes As well...

Regards,

Kristof
Avatar of rtod2

ASKER

Kberger, nice!

This works but still doesn't give a space prior to the value.
totalRevenueBox.Text = totalRevenue.ToString("c");

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of KBerger
KBerger

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial