?
Solved

MessageBox along with if and else statement

Posted on 2007-04-01
5
Medium Priority
?
219 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 1000 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

801 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