473,382 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help these programs not working!!!

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 1684
Markus
6,050 Expert 4TB
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 Expert 2GB
Nope, that's C++. Moved to C/C++ Forum.
Dec 10 '08 #3
Markus
6,050 Expert 4TB
@insertAlias
Thanks, iA. :D
Dec 10 '08 #4
Curtis Rutland
3,256 Expert 2GB
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 Expert 1GB
@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 Expert 2GB
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
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 Expert 2GB
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
@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
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...
3
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...
1
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...
1
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...
3
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 ...
0
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...
5
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 ...
0
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() ...
0
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...
13
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.