Writing a C# program - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Writing a C# program

cowgirl1996cowgirl1996 United StatesPosts: 6Member

Write a program for an Internet provider that displays a MessageBox asking users whether they want Internet access. If they do not, their total price is $0. If they do, display a second MessageBox asking whether they want limited access (at $10.95 per month) or unlimited access (at $19.95 per month). Display the total price in a third MessageBox. Title the program InternetAccess.

Here is my code so far:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Internet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult unlimited;
        DialogResult choice = MessageBox.Show("Internet Services are available as limited access at $10.95 per month \n and unlimited access at $19.95 per month.\n Do you want internet connection?",
        "Internet Service", MessageBoxButtons.YesNo);
        if (choice == DialogResult.Yes)
            unlimited = MessageBox.Show("Do you want unlimited package?", "Package", MessageBoxButtons.YesNo);
            if (unlimited == DialogResult.Yes);
            MessageBox.Show("Your price is $19.95 per month");
            else;
            MessageBox.Show("Your price is $10.95 per month");
            else;
            MessageBox.Show("display a total price of $0");
            }
    }
}

}

I'm not at all sure where I am going wrong!

Comments

  • mk44mk44 UKPosts: 9Member

    Well for a start an 'if' statement doesn't end in a semi-colon, and neither does 'else'.

  • mazanujmazanuj Ukraine, KievPosts: 18Member

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult unlimited;
        DialogResult choice = MessageBox.Show(@"Internet Services are available as limited access at $10.95 per month \n and unlimited access at $19.95 per month. \n Do you want internet connection?", "Internet Service", MessageBoxButtons.YesNo);
        if (choice == DialogResult.Yes)
        {
            unlimited = MessageBox.Show("Do you want unlimited package?", "Package", MessageBoxButtons.YesNo);
            if (unlimited == DialogResult.Yes)                
                MessageBox.Show("Your price is $19.95 per month");                
            else MessageBox.Show("Your price is $10.95 per month");
        }
        else MessageBox.Show("display a total price of $0");
    }
  • HTMLKingKongHTMLKingKong UKPosts: 6Member

    Although not strictly speaking necessary i would go with curly braces on all if statements for readability.

    if (diaResult2 == DialogResult.Yes)
    {    
        runningTotal = 10.95F;
    }

    I presume you have this working now.

Sign In or Register to comment.