943,999 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5105
  • C++ RSS
Nov 29th, 2006
0

currency conversion program error

Expand Post »
ive created this currency conversion program
which converts the currency then adds commission, but its got a error saying undefined symbol true in function main
can someone help me ive only got the one error with it.


C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
  2.  
  3. int choice;
  4. double pounds;
  5. double USdollar;
  6. double Euro;
  7. double interest;
  8.  
  9. int main(){
  10. cout << "Select what you want to convert." <<endl;
  11. cout << "1.Pounds to US dollar." <<endl;
  12. cout << "2.Pounds to Euro." << endl;
  13. cin >> choice;
  14.  
  15. while (true){
  16.  
  17. //converts pounds to US dollars
  18. if (choice == 1){
  19. cout << "Please enter amount you want to convert." <<endl;
  20. cin >> pounds;
  21. USdollar = pounds * 0.5; //change the conversion rate
  22. cout << USdollar<< endl;
  23. if (pounds <= 1000){
  24. cout << "Interest rate is 1% of this amount." <<endl;
  25. interest = USdollar + (USdollar * 0.01);
  26. cout << interest << endl;
  27. }
  28. if (pounds > 1000){
  29. cout << "Interest rate is 3% of this amount." <<endl;
  30. interest = USdollar + (USdollar * 0.03);
  31. cout << interest << endl;
  32. }break;
  33. }
  34. //converts pounds to euro
  35. if (choice == 2){
  36. cout << "Please enter amount you want to convert." <<endl;
  37. cin >> pounds;
  38. Euro = pounds * 0.3; //change the conversion rate
  39. cout << Euro<< endl;
  40. if (pounds <= 1000){
  41. cout << "Interest rate is 1% of this amount." <<endl;
  42. interest = Euro + (Euro * 0.01);
  43. cout << interest << endl;
  44. }
  45. if (pounds > 1000){
  46. cout << "Interest rate is 3% of this amount." <<endl;
  47. interest = Euro + (Euro * 0.03);
  48. cout << interest << endl;
  49. }break;
  50. }
  51. if (choice != 1 && choice !=2){
  52. cout <<"Invalid choice. Enter again."<<endl;
  53. }
  54. }return 0;
  55. }
Last edited by sunny123; Nov 29th, 2006 at 12:11 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 29th, 2006
0

Re: currency conversion program error

true has not been defined. Define it.
Last edited by WaltP; Nov 29th, 2006 at 12:42 pm.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Nov 29th, 2006
0

Re: currency conversion program error

It works fine on my compiler :-S
Try declaring a boolean variable and have that in the while loop
C++ Syntax (Toggle Plain Text)
  1. bool keepLooping = true;
  2.  
  3. ...
  4.  
  5. while (keepLooping)
  6. {
  7. ...
  8. }

Or simply use the forever loop
C++ Syntax (Toggle Plain Text)
  1. for (;;)
  2. {
  3. ...
  4. }
Reputation Points: 13
Solved Threads: 2
Junior Poster in Training
may4life is offline Offline
57 posts
since Oct 2006
Nov 29th, 2006
0

Re: currency conversion program error

thankyou
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sunny123 is offline Offline
10 posts
since Oct 2006
Nov 29th, 2006
0

Re: currency conversion program error

Quote originally posted by sunny123 ...
C++ Syntax (Toggle Plain Text)
  1. #include <iostream.h>
iostream.h is outdated - use iostream instead:
http://www.devx.com/tips/Tip/14447
(you also either need to put using namespace std; after the inclusion of iostream, or place std:: in front of each Standard Template Library object)

My suspection of "undefined symbol true" is that the compiler is in 'C' mode or something... perhaps in the configuration or something you can change it. In any case, it works fine on mine (gcc).

Quote originally posted by may4life ...
Try declaring a boolean variable and have that in the while loop
Code:
C++ Syntax (Toggle Plain Text)
  1. bool keepLooping = true;
  2.  
  3. ...
  4.  
  5. while (keepLooping)
  6. {
  7. ... }
What an awful way of doing it. Firstly, if the compiler doesn't recognize true in the while loop, what makes you think it will recognize it in a variable assignment? Secondly, it's much shorter to simply create a while loop with '1' like the following:
C++ Syntax (Toggle Plain Text)
  1. while(1) {
  2. ...
  3. }
That should work for ya.
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

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: four function in maim II
Next Thread in C++ Forum Timeline: Stuck





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


Follow us on Twitter


© 2011 DaniWeb® LLC