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 Test2
{
struct Drinks
{
public string drinkName;
public string drinkCost;
public string drinkInventory;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[,] drinksChoice = new string[,] {{"Cola", "1.00", "20"},{"Root Beer", "1.00", "20"},
{"Lemon Lime", "1.00", "20"},{"Grape Soda", "1.50", "20"},
{"Cream Soda", "1.50", "20"}};
int totalSold = 0;
int totalSales = 0;
int colaSold = 20;
int rootBeerSold = 20;
int lemonLimeSold = 20;
int grapeSodaSold = 20;
int creamSodaSold = 20;
int total = 0;
Drinks option = new Drinks();
private void colaPictureBox_Click_1(object sender, EventArgs e)
{
colaSold--;
option.drinkName = drinksChoice[0, 0];
option.drinkCost = drinksChoice[0, 1];
option.drinkInventory = drinksChoice[0, 2];
colaRemainingLabel.Text = colaSold.ToString();
total++;
totalSales = total;
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
if (colaSold < 1)
{
MessageBox.Show("Sorry, Cola is Sold Out");
}
}
private void exitButton_Click_1(object sender, EventArgs e)
{
this.Close();
}
private void rootBeer_Click(object sender, EventArgs e)
{
rootBeerSold--;
option.drinkName = drinksChoice[0, 0];
option.drinkCost = drinksChoice[0, 1];
option.drinkInventory = drinksChoice[0, 2];
rootBeerLabel.Text = rootBeerSold.ToString();
total++;
totalSales = total;
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
if (rootBeerSold < 1)
{
MessageBox.Show("Sorry, Root Beer is Sold Out");
}
}
private void lemonLime_Click_1(object sender, EventArgs e)
{
lemonLimeSold--;
option.drinkName = drinksChoice[0, 0];
option.drinkCost = drinksChoice[0, 1];
option.drinkInventory = drinksChoice[0, 2];
lemonLimeRemainingLabel.Text = lemonLimeSold.ToString();
total++;
totalSales = total;
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
if (lemonLimeSold < 1)
{
MessageBox.Show("Sorry, Lemon Lime is Sold Out");
}
}
private void grapeSoda_Click(object sender, EventArgs e)
{
grapeSodaSold--;
option.drinkName = drinksChoice[0, 0];
option.drinkCost = drinksChoice[0, 1];
option.drinkInventory = drinksChoice[0, 2];
grapeRemainingLabel.Text = grapeSodaSold.ToString();
total++;
totalSales = total;
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
if (grapeSodaSold < 1)
{
MessageBox.Show("Sorry, Grape is Sold Out");
}
}
private void creamSoda_Click(object sender, EventArgs e)
{
creamSodaSold--;
option.drinkName = drinksChoice[0, 0];
option.drinkCost = drinksChoice[0, 1];
option.drinkInventory = drinksChoice[0, 2];
creamSodaRemainingLabel.Text = creamSodaSold.ToString();
total++;
totalSales = total;
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
if (creamSodaSold < 1)
{
MessageBox.Show("Sorry, Cream Soda is Sold Out");
}
}
}
}
5 Replies - 4831 Views - Last Post: 27 November 2011 - 03:42 PM
#1
Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:20 PM
What in the world did I do wrong? I can't figure out why this stupid zero keeps showing up before the dollar sign in the totalSalesLabel. Any input would be awesome! Thanks.
Replies To: Stupid 0 before my dollar sign, how do I get rid of it?
#2
Re: Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:30 PM
Reminder to all: This is a homework question so completed source code is not allowed.
Chuck: YOu dropped in 125 lines of code with no reference to which output you are talking about. HOw about not making us scrub through it all. Which line are you talking about?
Sadly schools don't seem to be teaching students how to debug their own work.
See FAQ #5 for debugging tutorials
FAQ (Frequently Asked Questions - Updated Nov 2011
Chuck: YOu dropped in 125 lines of code with no reference to which output you are talking about. HOw about not making us scrub through it all. Which line are you talking about?
Sadly schools don't seem to be teaching students how to debug their own work.
See FAQ #5 for debugging tutorials
FAQ (Frequently Asked Questions - Updated Nov 2011
Spoiler
#3
Re: Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:30 PM
Because you do a "totalSold.ToString()" prior to totalSales.ToString("c") where you set the label. You have never used this variable totalSold (so it is zero) and you make it a string so you are appending it on the front of the totalSales.
Make it this line...
That should fix you up.
Make it this line...
totalSalesLabel.Text = totalSales.ToString("c");
That should fix you up.
#4
Re: Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:31 PM
Hi,
Could it be something to do with this line (line 70):
What's the value of totalSold there?
Could it be something to do with this line (line 70):
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
What's the value of totalSold there?
#5
Re: Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:34 PM
Just a review of your code:
It has a horrible amount of duplicate code. Every button click is identical to each other except for the product. This really should be a case of the soda type and cost being sent as parameters to single method that does everything you duplicated several times.
And your problem is a good example of *WHY*
You have this line in every button click handler:
So in order to fix your problem, you have to fix it 'n' times: Once for every handler that you put this line in.
It has a horrible amount of duplicate code. Every button click is identical to each other except for the product. This really should be a case of the soda type and cost being sent as parameters to single method that does everything you duplicated several times.
And your problem is a good example of *WHY*
You have this line in every button click handler:
totalSalesLabel.Text = totalSold.ToString() + totalSales.ToString("c");
So in order to fix your problem, you have to fix it 'n' times: Once for every handler that you put this line in.
#6
Re: Stupid 0 before my dollar sign, how do I get rid of it?
Posted 27 November 2011 - 03:42 PM
Wow! Lots of helpful info, especially the FAQ's. I really appreciate the input and the help. I'm doing this online so it's hard to get any help.
Thanks for the tips, I appreciate it.
Thanks for the tips, I appreciate it.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|