Solved

MessageBox along with if and else statement

Posted on 2007-04-01
5
210 Views
Last Modified: 2013-12-16
I am new in C#.
I am creating a MessageBox for user option ,  please help me to fix the code, I am new in C#
Depending on the answer (NO = local plan or YES = nationwide plan), display a second MessageBox showing the appropriate prices:  $23.99 a month for the local plan or $59.99 a month for the nationwide plan.  

Here is the code, please help me to fix this  code
************************

 

namespace Wireless
{
      using System;
      using System.Windows.Forms;
      public class Wireless
      
      {
            public static void Main()
            {
                  string question="Do you want a nationwide plan?";
                  string caption ="Wireless Plan";
                  double price = 23.00;
                  if (MessageBox.Show(question, caption,MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes)
                        price +=36.99;
                  {
                         
                              MessageBox.Show(price.ToString("C") + " a month for the Nation wide plan");
                  }
             
                  else
                        
                        (MessageBox.Show(question, caption,MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.No);
                        price +=0.99;
                                                      
                                                             
            {
                              MessageBox.Show(price.ToString("C") + " a month for the local plan");
                        }
            }

      }
}
 




0
Comment
Question by:sfareed
  • 3
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18832597
public static void Main()
            {
                  string question="Do you want a nationwide plan?";
                  string caption ="Wireless Plan";
                  double price = 23.00;
                  if (MessageBox.Show(question, caption,MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes)
                  {
                        price +=36.99;
                       MessageBox.Show(price.ToString("C") + " a month for the Nation wide plan");
                  }
                  else
                  {      
                        price +=0.99;
                        MessageBox.Show(price.ToString("C") + " a month for the local plan");
                  }
            }
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18832603
you might also make the follwing a bit easier to read:
> if (MessageBox.Show(question, caption,MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult.Yes)

DialogResult user_choice = MessageBox.Show(question, caption,MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (user_choice ==  DialogResult.Yes)
{
  ..
}
else
{
 ...
}
0
 

Author Comment

by:sfareed
ID: 18836231
Before I submit 250 points for you,
could you please let me know how can I add third option (cancel)on the message
box.
User has three option

1) Yes
2) No
3) Cancel(which gonna end the program.

thanks for your help
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 18836292
yes, using MessageBoxButtons.YesNoCancel



DialogResult user_choice = MessageBox.Show(question, caption,MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
switch (user_choice )
{
    case DialogResult.Yes:
           ...
    break;
    case DialogResult.No:
           ...
    break;
    case DialogResult.Cancel:
           ...
    break;
}
0
 

Author Comment

by:sfareed
ID: 18836311
I really appreciate your help

take care
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now