Web Forms

Don't know how to pass info or values to the next form

Page 1 of 1

13 Replies - 1420 Views - Last Post: 09 May 2010 - 08:23 AM

#1 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Web Forms

Posted 29 April 2010 - 06:25 AM

Hi,

I am having difficulties passing information to the next page if user clicks submit. I haven't really understand in my book how to do it, it only shows one way. This project is to allow a user to buy rodeo regular tickets at $15 and $25 for award event if they checked. The form ask user to enter the number of tickets and to check if wants an award event. Then they have submit their credit card information and personal address. I have three web page forms, which one is the default as an starting site, the second one is to click the submit button after done. Once they click the submit button it will show the amount owed...then the last page is to get a confirmation number if click in the hyperlink of that link. I don't know how to send information from one page to the other plus would like to add a validator if user forgets to fill out the first page. Any advice?

1. Default page
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page 
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;
    
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void submitOrderButton_Click(object sender, EventArgs e)
    {
           
        int quantityTickets = int.Parse(numberOfTicketsTextBox.Text);
        if (quantityTickets > 0)
        {
               totalOrderDecimal = quantityTickets * ticketsOrder;
        }
        else if (quantityTickets > 0 && awardsEventCheckBox.Checked)
        {
            totalOrderDecimal += quantityTickets * awardsOrder;
        }
        Server.Transfer("TicketOrder.aspx");
       
            
    }
}



2. The second page
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
          
    }
}

3.  Third page
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Confirmation : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Web Forms

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6081
  • View blog
  • Posts: 23,556
  • Joined: 23-August 08

Re: Web Forms

Posted 29 April 2010 - 06:53 AM

Moved to ASP.NET
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 29 April 2010 - 07:44 AM

Look into using either QueryStrings or Session variables to pass the information to the next page.
Was This Post Helpful? 1
  • +
  • -

#4 bluebear1608  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 03-June 08

Re: Web Forms

Posted 29 April 2010 - 08:29 AM

You could also try using cookies, they're quite simple to use
Was This Post Helpful? 0
  • +
  • -

#5 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Re: Web Forms

Posted 29 April 2010 - 10:45 PM

I tried session and other ways listed under help but I can't get the form to get the data pass yet, here is what I have for two forms. Any more suggestions?
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class _Default : System.Web.UI.Page 
{
    [ThemeableAttribute(false)]
    [System.ComponentModel.TypeConverter(typeof(ValidatedControlConverter))]
    public string ControlToValidate { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {


    }
    void ServerValidation(object source, ServerValidateEventArgs args)
    {

        args.IsValid = (awardsEventCheckBox.Checked == true);

    }
    protected void submitOrderButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            validateMessageLabel.Text = "Page submitted successfully.";
        }
        else
        {
            validateMessageLabel.Text = "There is an error on the page.";
        }

        Session["Number of Tickets"] = numberOfTicketsTextBox.Text;
        Session["Awards Event"] = awardsEventCheckBox.Checked;
        Session["Credit Card Number"] = creditCardNumberTextBox.Text;
        Session["Expiration Date"] = expirationDateTextBox.Text;
        Session["Type of Credit Card"] = typeOfCreditCardDropDownList.SelectedItem;
        Session["Name"] = nameTextBox.Text;
        Session["Mailing Address"] = mailingAddressTextBox.Text;
        Session["City"] = cityTextBox.Text;
        Session["State"] = stateTextBox.Text;
        Session["Zip Code"] = zipCodeTextBox.Text;

        Server.Transfer("TicketOrder.aspx");
       
            
    }
}



Here is the TicketOrder form
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            TextBox NumberOfTickets = (TextBox)PreviousPage.FindControl("numberOfTicketsTextBox.Text");
            Session["Number of Tickets"] = NumberOfTickets;
            CheckBox AwardEvent = (CheckBox)PreviousPage.FindControl("awardsEventCheckBox.Checked");
            Session["Awards Event"] = AwardEvent;

            if (NumberOfTickets != null)
            {
                for (int x = 1; x > 0; x++)
                {
                    totalOrderDecimal = x * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";
                }
            }
            else if (AwardEvent != null)
            {
                for (int x = 1; x > 0; x++)
                {
                    totalOrderDecimal = x * awardsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";
                }
            }
        }
   
    }


Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 30 April 2010 - 07:28 AM

You are overwriting the values in your TicketOrder page. I'm not sure why you are getting the controls from the first page again. When you already have the values stored in the Sessions.

All you need to do is extract the data from the Session variable, not write to it again.

Here is an example of how to get the data from the session. Don't forget that you need to cast the value from the session into the correct data type.
//Set the session to a value of 10
Session["Number of Tickets"] = 10;

//Initialize a variable to hold the ticket count
int ticketCount = 0;

//Retrieve the count from the Session variable and cast it to type Integer
//ticketCount will now be equal to 10
ticketCount = Convert.ToInt32(Session["Number of Tickets"]);


Also, I am not sure what you are attempting to do in those loops, but you have created infinite loops. X is equal to 1 and you are telling it to continue running the loop while X is greater than 0. Well X will always be greater than 0 in this case.
Was This Post Helpful? 0
  • +
  • -

#7 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Re: Web Forms

Posted 04 May 2010 - 07:57 PM

Ok well I am trying this code now and still don't get any output.

First Page:
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class _Default : System.Web.UI.Page 
{

    protected void Page_Load(object sender, EventArgs e)
    {


    }
    void ServerValidation(object source, ServerValidateEventArgs args)
    {

        args.IsValid = (awardsEventCheckBox.Checked == true);

    }
    protected void submitOrderButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            validateMessageLabel.Text = "Page submitted successfully.";
        }
        else
        {
            validateMessageLabel.Text = "There is an error on the page.";
        }

        Session["Number of Tickets"] = numberOfTicketsTextBox.Text;
        Session["Awards Event"] = awardsEventCheckBox.Checked;
        Session["Credit Card Number"] = creditCardNumberTextBox.Text;
        Session["Expiration Date"] = expirationDateTextBox.Text;
        Session["Type of Credit Card"] = typeOfCreditCardDropDownList.SelectedItem;
        Session["Name"] = nameTextBox.Text;
        Session["Mailing Address"] = mailingAddressTextBox.Text;
        Session["City"] = cityTextBox.Text;
        Session["State"] = stateTextBox.Text;
        Session["Zip Code"] = zipCodeTextBox.Text;

        Server.Transfer("TicketOrder.aspx");
       
            
    }



Second Page TicketOrder page:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            CheckBox AwardEvent = (CheckBox)PreviousPage.FindControl("awardsEventCheckBox.Checked");
            Session["Awards Event"] = AwardEvent;
            Session["Number of Tickets"] = 10;


            if (Session["Number of Tickets"] != null)
            {
                for (int ticketCount = 0; ticketCount > 10; ticketCount++)
                {
                    ticketCount = Convert.ToInt32(Session["Number of Tickets"]);
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (AwardEvent != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }
            }       
        }
   
    }

}





View PostJayman, on 30 April 2010 - 06:28 AM, said:

You are overwriting the values in your TicketOrder page. I'm not sure why you are getting the controls from the first page again. When you already have the values stored in the Sessions.

All you need to do is extract the data from the Session variable, not write to it again.

Here is an example of how to get the data from the session. Don't forget that you need to cast the value from the session into the correct data type.
//Set the session to a value of 10
Session["Number of Tickets"] = 10;

//Initialize a variable to hold the ticket count
int ticketCount = 0;

//Retrieve the count from the Session variable and cast it to type Integer
//ticketCount will now be equal to 10
ticketCount = Convert.ToInt32(Session["Number of Tickets"]);


Also, I am not sure what you are attempting to do in those loops, but you have created infinite loops. X is equal to 1 and you are telling it to continue running the loop while X is greater than 0. Well X will always be greater than 0 in this case.

Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 05 May 2010 - 06:58 AM

When you debug your application, does your code get past the first IF statement, ie. if (PreviousPage != null)?

Try modifying your code to the following and see if you get the results you expect. Basically you are going to remove/comment the IF statement. I also made a couple of other small modifications. You don't need to get the controls from the first page, since the values you need are stored in the session variables.

Just check if those session variables are null before attempting to use them.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (PreviousPage != null)
        //{
            //CheckBox AwardEvent = (CheckBox)PreviousPage.FindControl("awardsEventCheckBox");
            //Session["Awards Event"] = AwardEvent;
            //Session["Number of Tickets"] = 10;


            if (Session["Number of Tickets"] != null)
            {
                for (int ticketCount = 0; ticketCount > 10; ticketCount++)
                {
                    ticketCount = Convert.ToInt32(Session["Number of Tickets"]);
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (Session["Awards Event"] != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }
            }       
        //}
   
    }

}


Was This Post Helpful? 0
  • +
  • -

#9 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Re: Web Forms

Posted 05 May 2010 - 09:47 PM

Thank you Jayman, yes i removed the comment and the submit button leads to the ticketOrder page but nothing shows only the links for confirmation and to go back home. Hum, not sure now, don't know whats wrong. I did exactly what you did in the second page. :(

View PostJayman, on 05 May 2010 - 05:58 AM, said:

When you debug your application, does your code get past the first IF statement, ie. if (PreviousPage != null)?

Try modifying your code to the following and see if you get the results you expect. Basically you are going to remove/comment the IF statement. I also made a couple of other small modifications. You don't need to get the controls from the first page, since the values you need are stored in the session variables.

Just check if those session variables are null before attempting to use them.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (PreviousPage != null)
        //{
            //CheckBox AwardEvent = (CheckBox)PreviousPage.FindControl("awardsEventCheckBox");
            //Session["Awards Event"] = AwardEvent;
            //Session["Number of Tickets"] = 10;


            if (Session["Number of Tickets"] != null)
            {
                for (int ticketCount = 0; ticketCount > 10; ticketCount++)
                {
                    ticketCount = Convert.ToInt32(Session["Number of Tickets"]);
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (Session["Awards Event"] != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }
            }       
        //}
   
    }

}


Was This Post Helpful? 0
  • +
  • -

#10 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 06 May 2010 - 07:40 AM

The issue that remains is the FOR loop. You have set the ticketCount equal to 0, but the condition is that ticketCount must be greater than 10 for the loop to execute. This loop will never execute.

I believe this is what you meant to do:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
            
            if (Session["Number of Tickets"] != null)
            {
                //Get the total # of tickets ordered
                int totalTickets = Convert.ToInt32(Session["Number of Tickets"]);             

                //Loop until you've reached the # of tickets ordered
                for (int ticketCount = 0; ticketCount < totalTickets; ticketCount++)
                {
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (Session["Awards Event"] != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }
            }
    }

}


Was This Post Helpful? 0
  • +
  • -

#11 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Re: Web Forms

Posted 07 May 2010 - 07:43 PM

Ajjj, i tried that too but nothing shows in the TicketOrder page, very annoying :(

View PostJayman, on 06 May 2010 - 06:40 AM, said:

The issue that remains is the FOR loop. You have set the ticketCount equal to 0, but the condition is that ticketCount must be greater than 10 for the loop to execute. This loop will never execute.

I believe this is what you meant to do:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
            
            if (Session["Number of Tickets"] != null)
            {
                //Get the total # of tickets ordered
                int totalTickets = Convert.ToInt32(Session["Number of Tickets"]);             

                //Loop until you've reached the # of tickets ordered
                for (int ticketCount = 0; ticketCount < totalTickets; ticketCount++)
                {
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (Session["Awards Event"] != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }
            }
    }

}


Was This Post Helpful? 0
  • +
  • -

#12 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 08 May 2010 - 09:13 AM

Post your current code for both pages again. Perhaps there is something I've missed.
Was This Post Helpful? 0
  • +
  • -

#13 muychang  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 12-October 09

Re: Web Forms

Posted 08 May 2010 - 10:37 PM

Here is the first page
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


public partial class _Default : System.Web.UI.Page 
{

    protected void Page_Load(object sender, EventArgs e)
    {


    }
    void ServerValidation(object source, ServerValidateEventArgs args)
    {

        args.IsValid = (awardsEventCheckBox.Checked == true);

    }
    protected void submitOrderButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            validateMessageLabel.Text = "Page submitted successfully.";
        }
        else
        {
            validateMessageLabel.Text = "There is an error on the page.";
        }

        Session["Number of Tickets"] = numberOfTicketsTextBox.Text;
        Session["Awards Event"] = awardsEventCheckBox.Checked;
        Session["Credit Card Number"] = creditCardNumberTextBox.Text;
        Session["Expiration Date"] = expirationDateTextBox.Text;
        Session["Type of Credit Card"] = typeOfCreditCardDropDownList.SelectedItem;
        Session["Name"] = nameTextBox.Text;
        Session["Mailing Address"] = mailingAddressTextBox.Text;
        Session["City"] = cityTextBox.Text;
        Session["State"] = stateTextBox.Text;
        Session["Zip Code"] = zipCodeTextBox.Text;

        Server.Transfer("TicketOrder.aspx");
       
            
    }
}



Second page
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class TicketOrder : System.Web.UI.Page
{
    const decimal ticketsOrder = 15;
    const decimal awardsOrder = 25;
    decimal totalOrderDecimal;

    protected void Page_Load(object sender, EventArgs e)
    {
            if (Session["Number of Tickets"] != null)
            { 
                // Get the total # of tickets ordered
                int  totalTickets = Convert.ToInt32(Session["Number of Tickets"]);

                for (int ticketCount = 0; ticketCount > totalTickets; ticketCount++)
                {                   
                    totalOrderDecimal = ticketCount * ticketsOrder;
                    thankYouLabel.Text = "Thank you for your order";
                    orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    if (Session["Awards Event"] != null)
                    {
                        totalOrderDecimal = ticketCount * awardsOrder;
                        thankYouLabel.Text = "Thank you for your order";
                        orderTicketLabel.Text = "A total of " + totalOrderDecimal +
                        " has been charged to your credit card";

                    }
                }   
        }
   
    }

}


Was This Post Helpful? 0
  • +
  • -

#14 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Web Forms

Posted 09 May 2010 - 08:23 AM

You need to change the condition of your FOR loop. Change the greater than sign '>' to a less than '<' sign.

If it is easier, think of the condition of a FOR loop as a WHILE loop. So this condition, ticketCount > totalTickets, is saying 'loop WHILE ticketCount is greater than totalTickets'. Lets say the user is ordering a total of 10 tickets. Then the current value for ticketCount is 0 and the value for totalTickets is 10. ticketCount is not greater than totalTickets, so the loop will never run.

Keep in mind you are counting up from 0 to the total number of tickets ordered.

What you want the condition of the loop to say is, 'loop WHILE ticketCount is less than totalTickets'. So you change the sign to '<' and now your loop will execute a total of 10 times before exiting.

Make the following change to your FOR loop.
for (int ticketCount = 0; ticketCount < totalTickets; ticketCount++)


I see some other potential problems with how you are calculating your totals. I will let you have a crack at those first, if you get stuck you know where we are. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1