if staement

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

Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

if staement

 
0
  #1
Oct 19th, 2008
  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 206
Reputation: grumpier has a spectacular aura about grumpier has a spectacular aura about 
Solved Threads: 31
grumpier grumpier is offline Offline
Posting Whiz in Training

Re: if staement

 
0
  #2
Oct 19th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 273
Reputation: Sci@phy will become famous soon enough Sci@phy will become famous soon enough 
Solved Threads: 42
Sci@phy's Avatar
Sci@phy Sci@phy is offline Offline
Posting Whiz in Training

Re: if staement

 
1
  #3
Oct 19th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 101
Reputation: Se7Olutionyg has a little shameless behaviour in the past 
Solved Threads: 0
Se7Olutionyg Se7Olutionyg is offline Offline
Junior Poster

Re: if staement

 
0
  #4
Oct 20th, 2008
Originally Posted by grumpier View Post
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 .??
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 280
Reputation: joshmo is an unknown quantity at this point 
Solved Threads: 19
joshmo joshmo is offline Offline
Posting Whiz in Training

Re: if staement

 
0
  #5
Oct 21st, 2008
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: if staement

 
0
  #6
Oct 21st, 2008
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:

  1. else if ( 4000000 < ammwater < 10000000 )

Change it to:

  1. else if ( 4000000 < ammwater && ammwater < 10000000 )
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC