Solved

MessageBox along with if and else statement

Posted on 2007-04-01
5
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

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 143

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 143

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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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