Need help with decimal program.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2009
Posts: 27
Reputation: Kioti16 is an unknown quantity at this point 
Solved Threads: 0
Kioti16 Kioti16 is offline Offline
Light Poster

Need help with decimal program.

 
0
  #1
Jul 26th, 2009
I made this program that should be very easy but it does not work.
When I try to run it, it should take the price and add tax to it but it comes up with a crazy decimal number like: 7.74335e+268.
What should I do I tried everything.

I #include everything so sorry about the long text.
Attached Files
File Type: cpp Cash Register.cpp (1.3 KB, 4 views)
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: Need help with decimal program.

 
0
  #2
Jul 26th, 2009
what compiler are u using?
Argha Sen

Ask and it will be opened for u
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 29
Reputation: arghasen is an unknown quantity at this point 
Solved Threads: 4
arghasen arghasen is offline Offline
Light Poster

Re: Need help with decimal program.

 
0
  #3
Jul 26th, 2009
hey your program is solved
next time pls indent properly
just do the changes done in this portion of your code

cout <<"Product price $";

cin >> P;

TP=P*T; //Calculates product price with tax *Here is the problem*//

cout <<"Total price $"<<TP<<endl;

cout <<"Out of $";

cin >> TA;

M=TP-TA;
Last edited by arghasen; Jul 26th, 2009 at 4:03 am.
Argha Sen

Ask and it will be opened for u
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 66
Reputation: djextreme5 is on a distinguished road 
Solved Threads: 4
djextreme5's Avatar
djextreme5 djextreme5 is offline Offline
Junior Poster in Training

Re: Need help with decimal program.

 
0
  #4
Jul 26th, 2009
The problem can be easiely solved by ROUNDING the output number to a certain degree.

  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. double i = 0.546546, ii = 2.365463847698;
  8.  
  9. cout << fixed;
  10. cout << setprecision(3) << i * ii << endl;
  11.  
  12. return 0;
  13. }

edit ::

Here is my version of your code...

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <process.h>
  4. #include <conio.h>
  5. #include <iostream>
  6. #include <fstream>
  7. #include <stdlib.h>
  8. #include <time.h>
  9. #include <math.h>
  10. #include <string>
  11. #include <windows.h>
  12. using namespace std;
  13. string str;
  14.  
  15. int main(int nNumberofArgs, char* pszArgs[]) {
  16. //Coding starts here//
  17. double P; //Product price//
  18. double T = 0.07; //Tax for product//
  19. double TP; //Total price after tax//
  20. double TA; //Tendered//
  21. double M; //Misc//
  22. string choice; //After calc choice//
  23.  
  24. bridge: //The bridge of the program//
  25. cout <<" *------------------------------------------------*\n"
  26. <<" | Welcome To The Automated Cash Register Program |\n"
  27. <<" *------------------------------------------------*\n\n";
  28. cout <<"Product price $";
  29. cin >> P;
  30. TP = (P * T) + P;//Calculates product price with tax *Here is the problem*//
  31. cout <<"Total price $"<<TP<<endl;
  32. cout <<"Out of $";
  33. cin >> TA;
  34. M=TA-TP;
  35. cout <<"Change due $"<<M<<endl;
  36. invalid:
  37. cout <<"\n Type 'q' and hit enter to quit,\n"
  38. <<"or type 'c'and hit enter to continue: ";
  39. cin >> choice;
  40. if(choice=="q") {
  41. return 0; }
  42.  
  43. if(choice=="c") {
  44. system("CLS");
  45. goto bridge; }
  46.  
  47. else {
  48. cout <<"Invalid input, try again.";
  49. goto invalid; }
  50.  
  51.  
  52. }

Also, you do not know C++ basics. For example, = and == are different. = Assigns values to a variable and == checks two given conditions for example,.

after executing a if statement like this,

if (var1 = 10)
{}

the var1 variable will hold the value 10...

however, if its like this,

if (var1 == 10)
{}

then it CHECKS the value of var1 to be 10.
Last edited by djextreme5; Jul 26th, 2009 at 2:03 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC