473,792 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help these programs not working!!!

3 New Member
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. int main()
  8. {    
  9.  int code = 0;
  10.  int charges = 0;
  11.  
  12.  //enter input data
  13.  cout << "State code: ";
  14.  cin >> code;
  15.  cout << "Shipping charges: ";
  16.  cin >> charges;
  17.  
  18.  switch (code)
  19.  {
  20.  case 1:
  21.          charges = 25;
  22.          break;
  23.  case 2:
  24.  case 5:
  25.  case 6:
  26.          charges = 30;
  27.          break;
  28.  case 3:
  29.  case 4:
  30.         charges = 40;
  31.         break;
  32.  default:
  33.          cout << "Incorrect state code" << endl;
  34.  }    //end switch
  35.  
  36.  //display charges
  37.  cout << "Charges: " << charges << endl;
  38.  
  39.     return 0;
  40. }   //end of main function
  41.  
  42. It shows no errors on build but when go to enter number it does not display the charges? Have worked and worked on it cannot figure it out would appreciate some help in this matter as quick as possible. I am a newbie and I am really struggling!! same thing with the Net one below!!
  43.  
  44. #include <iostream> 
  45. #include <string>
  46. #include <iomanip>
  47.  
  48. using std::cout;
  49. using std::cin;
  50. using std::endl;
  51. using std::fixed;
  52. using std::setprecision;
  53.  
  54. int main()
  55. {
  56.     double hours = 0.0;
  57.     double rate  = 0.0;
  58.     double gross = 0.0;
  59.  
  60.     //enter input data
  61.     cout << "Hours worked: ";
  62.     cin >> hours;
  63.     cout << "Pay rate: ";
  64.     cin >> rate;
  65.  
  66.     //validate hours
  67.     if (hours <= 0.0)
  68.         cout << "The hours worked must be greater than 0." << endl;
  69.     //validate rate
  70.     else if (rate <= 0.0)
  71.         cout << "The pay rate must be greater than 0." << endl;
  72.     //calculate gross pay
  73.     else if (hours <= 40.0)
  74.         gross = hours * rate;
  75.     else gross = 40.0 * rate + (hours - 40.0) * rate * 1.5;
  76.     //end ifs
  77.  
  78.     //display gross pay
  79.     cout << fixed << setprecision(2);
  80.     cout << "The gross pay for working " << hours << " hours at $"
  81.         << rate << " per hour is $" << gross << endl;
  82.  
  83.     return 0;
  84. }   //end of main function
Again would really appreciate all the help! Have a wonderful Holiday Season.
Dec 10 '08 #1
9 1708
Markus
6,050 Recognized Expert Expert
Some things I should point out
  1. You didn't use [code] tags when posting code,
  2. You've flat out asked for help with no information on the problem,
  3. You didn't provide a meaningful title and
  4. You've posted the question in the wrong forum.

Now, I see you're a newbie, so we'll let you off for now.

Please read the Posting Guidelines to familiarize yourself with our way of life.

Thanks,
Markus.

PS - I wrote a whole load here, explaining what he should do now and in future questions, but, for some reason, the website refused to respond, and I lost my post. Awesome!
PSS - I'll wait for someone else to move this, because I don't know the language it is in. I'm guessing Java?
Dec 10 '08 #2
Curtis Rutland
3,256 Recognized Expert Specialist
Nope, that's C++. Moved to C/C++ Forum.
Dec 10 '08 #3
Markus
6,050 Recognized Expert Expert
@insertAlias
Thanks, iA. :D
Dec 10 '08 #4
Curtis Rutland
3,256 Recognized Expert Specialist
OK, here's the thing. There's nothing technically wrong with either of these programs. They both compile and run just fine.

However, with a console app, usually the console closes when the app is done running.

It is quite possible that the correct output is being sent but the console is closing too fast for you to see it.

Try adding this line:
Expand|Select|Wrap|Line Numbers
  1. system("pause");
right before the return 0; calls.

Also, I really can't follow the logic in the first program. You ask the user to input the code and the charges, but then you set the charges based on the code. Why ask for input if you are just going to override it?
Dec 10 '08 #5
YarrOfDoom
1,247 Recognized Expert Top Contributor
@insertAlias
I've read in another thread that this isn't always the best way to go.
http://bytes.com/topic/c/answers/857...lp#post3442082

Another way is to just launch the command line, and then launch the program from there.
Dec 10 '08 #6
Curtis Rutland
3,256 Recognized Expert Specialist
Well, I'm by absolutely no means a C++ expert. It's just a quick way I thought of to test his problem, if he's using windows.
Dec 10 '08 #7
mgrubbs
3 New Member
What it amounts to is when I enter the code it is suppose to pop up the shipping charge when I go into to start without debugging it is suppose to pop up enter code then I put 1 or whatever code for a shipping charge then it is suppose to pop up that number. That is the problem it is going to the enter the code and when I do it does not come up with the shipping charge. Maybe that will help some. I am a newbie and really confused to say the least. Appreciate all your help
Dec 10 '08 #8
Curtis Rutland
3,256 Recognized Expert Specialist
OK, honestly I don't understand your last post.

Did you try what I said?

Look the flow of your first program right now is:
Prompt
input
Prompt
input
switch logic
Display
Exit

And if you don't inject some kind of stop or pause between the Display and Exit, you'll never actually see what was displayed.

I copy/pasted your code, and added the system("pause") ; line, and it worked for me.

Your logic, on the other hand, I can't help you with until you more clearly explain the flow of your program.
Dec 10 '08 #9
mgrubbs
3 New Member
@insertAlias
tried your suggestion but did not work will look at the othe option you stated.Thanks again for your help, Mark
Dec 11 '08 #10

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

Similar topics

2
1871
by: Glenn | last post by:
Dynamic help topic links show properly and search brings up links, but when any link is clicked I receive a "Page Cannot be displayed message in the Explorer window and the title bar of Visual Studio reports that it cannot find server. What server is this? The start page works fine going to the internet and my normal Internet Explorer is working fine. VS 2003 v. 7.1.3044 Framework v. 1.1.4322 -- Thanks for any help, suggestions before...
3
1253
by: Woody Splawn | last post by:
For reasons I have not yet identified my Help, Search and Help, Index has quit working. That is, in the VB IDE, from the Help menu, I can select Dynamic help or Contents and things work as expected. But when I select Index or Search, the tabs appear but when I click on the Search or Index tab nothing happens. Anyone have any idea what's going on?
1
1180
by: Colin | last post by:
Hi there. I have just got a new website. I have some VB.Net code that reads a text file. This works on my home computer. When I upload it to my website I need to know the path. <?php echo $_SERVER; ?> If I put the php file above (test.php) in the htdocs directory and navigate to http://www.mydomain.co.uk/test.php it tells me the path and
1
2457
by: Kenneth McDonald | last post by:
I am going to demonstrate my complete lack of understanding as to going back and forth between character encodings, so I hope someone out there can shed some light on this. I have always depended on the kindness of strangers... :-) I'm playing around with some very simplistic french to english translation. As some text to work with, I copied the following from a french news site:
3
1153
by: chrisjob012 | last post by:
hi guys... need some help....!! i am working on a form that looks like a calender....!!... in that form i have added a group box....!! during runtime 30 labels are inserted in it to look like a month display and the labels are added as control arrays........thats working almost fine.... but i would like to have context menu appear in these labels... i was trying to give the user an option like this when he right clicks.... add holiday,...
0
914
by: mrainey | last post by:
My server data is as follows:- PHP Version: 4.4.4 MySQL Version: 5.0.26-standard Server Software: Apache/2.0.55 (Red Hat) the website will not install when you type in the install.php the page comes up to start the process but when you fill in the infomation and click submit the page resets and does move on. can you help http://dating.mcrphotographers.co.uk is the temp site address i managed to install it manually but still got the...
5
1694
by: sesling | last post by:
I have a database field that stores 8 and 9 digit values. I need to calculate the sum value using the first 8 digits. ex.of stored numbers 123456781 234567892 45678903 987654321 calculation should use 12345678 23456789
0
782
by: Jack13 | last post by:
Hello, From a main program drawing on a PictureBox, i would like to call a second program (.exe) wich could design on the same PictureBox. I'd try this: Main: Private Sub Form_Load() Picture1.Line (100, 100)-(3000, 3000), vbBlue, B l& = Picture1.hDC RetVal = Shell("Projet2.exe " & Str$(l&), 1) End Sub
0
1048
by: Andrus | last post by:
I installed VCSE 2008 I need to read help in places where internet connection available. Local help installed with C# 2005 Express is very incomplete. For example clicking DataContractSerializer or XmlObjectSerializer topics in ms-help://MS.VSCC.v90/MS.msdnexpress.v90.en/dv_linqsql/html/252ed666-0679-4eea-b71b-2f14117ef443.htm
13
1695
by: paragpdoke | last post by:
Hello Everyone. Merry Christmas to all ! I'm a JavaScript newbie (and new to thescripts.com too). And I have problems in working with objects in JavaScript. The problem: <a href="JavaScript:functionName(object);">Click me</a> Somehow it calls toString for the object and rather than it being processed as an object, it is processed as a string. Details: I'm trying to build a documentation UI (using VBA plugin mztools) and the objects I...
0
9518
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9033
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2917
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.