Link to home
Start Free TrialLog in
Avatar of sfareed
sfareedFlag for United States of America

asked on

MessageBox along with if and else statement

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");
                        }
            }

      }
}
 




Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

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");
                  }
            }
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
{
 ...
}
Avatar of sfareed

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sfareed

ASKER

I really appreciate your help

take care