Solved

MessageBox along with if and else statement

Posted on 2007-04-01
5
212 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

How our DevOps Team Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

825 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