Wrox Programmer Forums
|
C# 4.0 aka C# 2010 General Discussion Discussions about the C# 4.0, C# 4, Visual C# 2010 language and tool not related to any specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 4.0 aka C# 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2013, 03:51 PM
Registered User
 
Join Date: Apr 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default PROGRAMMING ERROR PLEASE HELP

// im writting code and im stuck idk what else to try ive googled put breakpoints. please help here is my code im using visual studio 2010. thanks. here is my code... my errors exist in the 'if' statements in the bottom where i have the counter to see if the user is checking the boxes. more specifically the vitaminpack and the energy booster. code reads "invalid token 'if' in class, struct, or interface member declaration. and on the first extrasInterger++ it tells me the same thing except the ++ instead of the if. please help.

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 juicebarform
{
public partial class JuiceBarForm : Form
{
//Declare class variable.
private decimal itemPriceDecimal, totalOrderDecimal, totalSalesDecimal;
private int drinksInteger, ordersInteger;

public JuiceBarForm()
{
InitializeComponent();
}




private void Form1_Load(object sender, EventArgs e)
{



}

private void addToOrderButton_Click(object sender, EventArgs e)
{
//Add the current item price and quantity to the order
if (noSizeRadioButton.Checked)
{
MessageBox.Show("you must select a drink size.", "missing required entry");
}
else
{
try
{
int quantityInteger = int.Parse(quantityTextBox.Text);
if (quantityInteger != 0)
{
drinksInteger += quantityInteger;
totalOrderDecimal += itemPriceDecimal * quantityInteger;
orderCompleteButton.Enabled = true;

//Resset defaults for next item
noSizeRadioButton.Checked = true;
fruitJuiceRadioButton.Checked = true;
VitaminPackCheckBox.Checked = false;
energyBoosterCheckBox.Checked = false;
ladiesCheckBox.Checked = false;
itemPriceTextBox.Clear();
quantityTextBox.Text = "1";
}
else
{
MessageBox.Show("Please enter a quantity.", "Missing required entry");
}
}
catch (FormatException)
{
MessageBox.Show("Invalid quantity.", "data entry error");
quantityTextBox.Focus();
quantityTextBox.SelectAll();
}
}
}

private void orderCompleteButton_Click(object sender, EventArgs e)
{
//order complete, add to summary and clear order.
//Check if the last time was added to the total.
if(itemPriceTextBox.Text != "")
{
DialogResult responseDialogResult;
string messageString = "Current item not recorded. Add to order?";
responseDialogResult = MessageBox.Show(messageString,"Verify Last Drink Purchase",MessageBoxButtons.YesNo,MessageBoxIcon.Q uestion);
if(responseDialogResult == DialogResult.Yes)
{
addToOrderButton_Click(sender, e);
}
}
// Display amount due.
string dueString = "amount due" + totalOrderDecimal.ToString("C");
MessageBox.Show(dueString, "Order Complete");

//Add to summary totals
ordersInteger++;
totalSalesDecimal += totalOrderDecimal;

//reset buttons and total for new order.
summaryReportButton.Enabled =true;
orderCompleteButton.Enabled = false;
totalOrderDecimal = 0m;
}

private void summaryReportButton_Click(object sender, EventArgs e)
{
// DIsplay the summary information in a message box
string summaryString = "Drinks sold: " + drinksInteger.ToString()
+ ordersInteger.ToString() + "\n\n" + "Total Sales: "
+ totalSalesDecimal.ToString("C");
MessageBox.Show(summaryString, "Juice Bar Sales Summary",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

private void exitButton_Click(object sender, EventArgs e)
{
//End the application
this.Close();
}

private void twelveOunceRadioButton_CheckedChanged(object sender, EventArgs e)
{
//Calculate and display the price for the selected item
// Handles all the check boxes and radio buttons
int extrasInteger = 0;
if(twelveOunceRadioButton.Checked)
{
itemPriceDecimal = 3m;
}
else
if(sixteenOunceRadioButton.Checked)
{
itemPriceDecimal = 3.5m;
}
else
if(twentyOunceRadioButton.Checked)
itemPriceDecimal = 4m;
}
int extrasInteger = 0;
if (VitaminPackCheckBox.Checked)
{
extrasInteger++;
}
if (energyBoosterCheckBox.Checked)
{
extrasInteger++;
}
if(ladiesCheckBox.Checked)
{
extrasInteger++;
}
itemPriceDecimal += extrasInteger * .5m; // 50 cents for each extra.
itemPriceDecimal.Text = itemPriceDecimal.ToString("C");

}

Last edited by jordan_2324; April 6th, 2013 at 03:55 PM..
 
Old July 26th, 2013, 07:19 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still i have no idea about it. But after trace your code i will give you solution about your query.
 
Old March 14th, 2014, 12:52 AM
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

That error is telling you have an angle bracket out off place and it throwing scope off. In fact I see a missing bracket on the else if twentyonceradiobutton.check has closing bracket but no open bracket. You probably have a few more in there as well.

Last edited by mmorgan30; March 14th, 2014 at 12:57 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Office Programming jasu C# 0 July 24th, 2007 04:19 AM
Error in Office Programming melvik C# 7 August 17th, 2006 07:53 AM
error handling in asp.net e-commerce programming 123 All Other Wrox Books 0 October 19th, 2003 04:55 AM
.NET Network Programming Error TripleClamps All Other Wrox Books 0 August 13th, 2003 07:20 PM
.NET Network Programming Error TripleClamps .NET Web Services 0 August 13th, 2003 06:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.