473,586 Members | 2,776 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 1996
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\nWhi ch 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
2647
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 sane person. I was wondering about how a Python programmer should organize the multiple python source files that will be needed by their program. Is...
11
9458
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 *a = /* this is a comment "\*/"this is a string"/*" another comment */;
9
9697
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
13572
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 we say, inherited? -- a COBOL program with very little documentation that I've recompiled for debugging purposes. The compile/link/bind have all...
2
2413
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 cheese. It has four different difficulty levels and you have obsticles in your way (the amount depends on the difficulty level). The problem I am...
1
2882
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 displaying the results, return to the menu to let the user choose another formula or exit. #include <iostream> using namespace std; #include...
8
3186
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
1184
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 or warnings, the program wouldn't open up or do anything. It was running, though, and I had to close it via the processes tab, because I couldn't see...
0
854
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; use Apache::Request; .................................... .................................... my $a='hai';
0
7911
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6610
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.