473,508 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program to switch between packages, all 3 being chosen

11 New Member
I just need the following program to ask for a certain "package" and the user will enter either A, B, or C and then the according statement will pop up. Right now my program pops up with all three of the statements. Help would be appreciated.





Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     char package;
  7.  
  8.     cout << "Internet Service Provider\n\nWhich package would you like to purchase? --> ";
  9.     cin >> package;
  10.  
  11. if(package = A)
  12. {
  13.     cout << "**************************************************\n";
  14.     cout << "*                                                *\n";
  15.     cout << "* Internet Service Provider Package: A           *\n";
  16.     cout << "*                                                *\n";
  17.     cout << "*                              Bill: $19.95      *\n";
  18.     cout << "*                                                *\n";
  19.     cout << "* Thank you for your business*********************\n\n";
  20. }
  21.  
  22. if(package = B)
  23. {
  24.     cout << "**************************************************\n";
  25.     cout << "*                                                *\n";
  26.     cout << "* Internet Service Provider Package: B           *\n";
  27.     cout << "*                                                *\n";
  28.     cout << "*                              Bill: $39.95      *\n";
  29.     cout << "*                                                *\n";
  30.     cout << "* Thank you for your business*********************\n\n";
  31. }
  32.  
  33. if(package = C)
  34. {
  35.     cout << "**************************************************\n";
  36.     cout << "*                                                *\n";
  37.     cout << "* Internet Service Provider Package: C           *\n";
  38.     cout << "*                                                *\n";
  39.     cout << "*                              Bill: $79.95      *\n";
  40.     cout << "*                                                *\n";
  41.     cout << "* Thank you for your business*********************\n\n";
  42. }
  43.  
  44.     return 0;
  45. }
Sep 17 '07 #1
4 1990
rhitam30111985
112 New Member
I just need the following program to ask for a certain "package" and the user will enter either A, B, or C and then the according statement will pop up. Right now my program pops up with all three of the statements. Help would be appreciated.






#include <iostream>
using namespace std;

int main()
{
char package;

cout << "Internet Service Provider\n\nWhich package would you like to purchase? --> ";
cin >> package;

if(package = A)
{
cout << "************************************************* *\n";
cout << "* *\n";
cout << "* Internet Service Provider Package: A *\n";
cout << "* *\n";
cout << "* Bill: $19.95 *\n";
cout << "* *\n";
cout << "* Thank you for your business*********************\n\n";
}

if(package = B)
{
cout << "************************************************* *\n";
cout << "* *\n";
cout << "* Internet Service Provider Package: B *\n";
cout << "* *\n";
cout << "* Bill: $39.95 *\n";
cout << "* *\n";
cout << "* Thank you for your business*********************\n\n";
}

if(package = C)
{
cout << "************************************************* *\n";
cout << "* *\n";
cout << "* Internet Service Provider Package: C *\n";
cout << "* *\n";
cout << "* Bill: $79.95 *\n";
cout << "* *\n";
cout << "* Thank you for your business*********************\n\n";
}

return 0;
}

put an else ststement after each if block..

Expand|Select|Wrap|Line Numbers
  1. if(package=='A')
  2. {....}
  3. else
  4. if(package=='B')
  5. {...}
  6.  
and so on... the else statement will choose between two different blocks... otherwise all of them wud get excecuted...
Sep 17 '07 #2
rhitam30111985
112 New Member
oh . one more thing.. there is a logical error in the if statements...

if(package =b)

doesnt mean anything to the compiler since its just assigning something to the variable package its not a condition hence all the blocks get excecuted.. .. .. if u change it to :

if(package=='B')

then u may not need the else statement ... but add it anyway.. good programing practice...
Sep 17 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Also note that 'b' is not equal to 'B' in C/C++, you might want to account for both.

Another option besides the if-else chain is the switch statement (almost all of the way down on the page).
Sep 17 '07 #4
kipj77
11 New Member
Thank you very much, you saved me!!!!
Sep 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2639
by: Derek W | last post by:
Hello all, I have a few questions about the best way to organize a large Python program. This would be a large program with a GUI interface, too large to be put all in one script file by any...
11
9440
by: James Hu | last post by:
This program is long. I don't really want to bore everyone with the details, but it handles wierd cases like: /\ * this is a comment *\ / #define FOO ??/* this is not a comment */ char...
9
9682
by: wouter | last post by:
hey hi..... I wanna make a switch wich does this: if pagid is set do A, if catid is set do B, if projectid is set do C, else do D. So i was thinking something like this:
10
13543
by: OppThumb | last post by:
Hi, I've been searching this newsgroup for an answer to my question, and the closest I've come asks my question, but in reverse ("How to figure out the program from plan/package"). I've -- shall...
2
2405
by: Icarus27 | last post by:
Hello, I am making a program that runs off of a two dimentional array but I have made it into a game called MouseBot. I am trying to make the game so that you can move the mouse until you get the...
1
2877
by: confusedprogrammer | last post by:
In the program below i need to get it, so that it will keep going through the program asks all the question and displays the results and goes back to the beginning if the user didn't select. After...
8
3172
by: Srinu | last post by:
Hi all, If we compile the below piece of code, it gets compiled. But gives weird result. switch(x) { int y=2; case 1:
3
1181
by: Bellum | last post by:
Well I'm trying to learn C++ (know a little Python) and I wrote what was supposed to be a quick and easy four function calculator. Well, after finally getting the compiler to work without any errors...
0
850
by: pavanponnapalli | last post by:
hi, How can we use variables or packages of one program into another. Say my first program name is First.pl, where i write the code like this: use DBI; ...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7058
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.