943,885 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 898
  • C++ RSS
Oct 19th, 2008
0

if staement

Expand Post »
C++ Syntax (Toggle Plain Text)
  1. //water
  2. # include <iostream>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. char code;
  8. int acc;
  9. float ammwater;
  10. float total;
  11. //get the data
  12. cout << " Insert acc number : ";
  13. cin >> acc;
  14. cout << " Type the code : " ;
  15. cin >> code;
  16. cout << " Ammount of water : " ;
  17. cin >> ammwater;
  18. // get the code
  19. switch (code)
  20. {
  21. case 'H' :case 'h':
  22. cout << " The bill for account number " << acc<< " is for home use " << endl;
  23. total = 5.0 + ( ammwater * 0.0005 ) ;
  24. cout << " The total payment would be $ " <<total<< ". Thank you" << endl;
  25. break;
  26.  
  27. case 'C' : case 'c' :
  28. cout << " The bill for account number " << acc << "is for commercial use " << endl;
  29. if (ammwater <= 4000000 )
  30. {
  31. cout << " The total payment would be $ " <<1000<< ". Thank you" << endl;
  32. }
  33. else
  34. {
  35. total = 1000 + (ammwater - 4000000);
  36. cout << " The total payment would be $ " << total << ". Thank you" << endl;
  37. }
  38. break;
  39. case 'I' : case 'i ' :
  40. {
  41. cout << " The bill for account number " <<acc<< "is for industrial use" endl;
  42. if (ammwater <= 4000000 )
  43. {
  44. cout << " The total payment would be $ " <<1000<< ". Thank you" << endl;
  45. }
  46. else if ( 4000000 < ammwater < 10000000 )
  47. {
  48. cout << " The total payment would be $ " <<2000<< ". Thank you" << endl;
  49. else
  50. {
  51. cout << " The total payment would be $ " << 3000 << ". Thank you" << endl;
  52. }
  53. break;
  54. default :
  55.  
  56. cout << " Syntax error, insert the right code. " << endl;
  57. return code;
  58. }
  59.  
  60.  
  61. return 0;
  62. }

in line 39 , the program state the error : "overflow in implicit constant conversion "
correct for me please, thank you
Similar Threads
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Oct 19th, 2008
0

Re: if staement

10000000 is an integer constant, and is probably too large to be represented in the int type supported by your compiler. [That presumably means you are using 16 bit compiler].

Also, as someone said in your other thread, "if ( 4000000 < ammwater < 10000000 )" does not test if ammwater is between 4000000 and 10000000. Refer that other thread and read the explanation of that.
Reputation Points: 193
Solved Threads: 32
Posting Whiz in Training
grumpier is offline Offline
206 posts
since Aug 2008
Oct 19th, 2008
1

Re: if staement

I tried to count lines to see which one is line 39, and I managed it, but for future:
[code=cplusplus] please, not just [code]!!!

case 'I' : case 'i ' : Notice that second 'i ', do you see a difference between:
'i'
'i '

First is valid, second is invalid!
Change that first
Reputation Points: 110
Solved Threads: 43
Posting Whiz in Training
Sci@phy is offline Offline
279 posts
since Sep 2008
Oct 20th, 2008
0

Re: if staement

Click to Expand / Collapse  Quote originally posted by grumpier ...
10000000 is an integer constant, and is probably too large to be represented in the int type supported by your compiler. [That presumably means you are using 16 bit compiler].
sorry i DONT' KNOW WHAT YOU MEAN, you mean it was not my mistake right, and how to sove this problem .??
Reputation Points: 3
Solved Threads: 0
Junior Poster
Se7Olutionyg is offline Offline
108 posts
since Oct 2008
Oct 21st, 2008
0

Re: if staement

Reputation Points: 19
Solved Threads: 20
Posting Whiz in Training
joshmo is offline Offline
280 posts
since Oct 2007
Oct 21st, 2008
0

Re: if staement

A 32-bit system can store from about -2 billion to 2 billion in an integer. Something like that, so 10,000,000 is within that range. A 16 -bit system can store some thing like -32,000 to 32,000 in an integer, so 10,000,000 is outside of that range. This line is incorrect regardless:

C++ Syntax (Toggle Plain Text)
  1. else if ( 4000000 < ammwater < 10000000 )

Change it to:

C++ Syntax (Toggle Plain Text)
  1. else if ( 4000000 < ammwater && ammwater < 10000000 )
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008

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: Understanding Arrays
Next Thread in C++ Forum Timeline: Some sort of logical error





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


Follow us on Twitter


© 2011 DaniWeb® LLC