943,667 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 462
  • C++ RSS
Jul 26th, 2009
0

Need help with decimal program.

Expand Post »
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, 13 views)
Similar Threads
Reputation Points: 13
Solved Threads: 0
Light Poster
kernel>panic is offline Offline
44 posts
since Mar 2009
Jul 26th, 2009
0

Re: Need help with decimal program.

what compiler are u using?
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008
Jul 26th, 2009
0

Re: Need help with decimal program.

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.
Reputation Points: 10
Solved Threads: 5
Light Poster
arghasen is offline Offline
35 posts
since Nov 2008
Jul 26th, 2009
0

Re: Need help with decimal program.

The problem can be easiely solved by ROUNDING the output number to a certain degree.

C++ Syntax (Toggle Plain Text)
  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...

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 76
Solved Threads: 6
Junior Poster
djextreme5 is offline Offline
103 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: About default constructor...
Next Thread in C++ Forum Timeline: Including Header Files in a C++ GUI





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC