//water 
# include <iostream>
using namespace std;

int main()
{
char code;
int acc;
float ammwater;
float total;
//get the data
cout << " Insert acc number : ";
cin >> acc;
cout << " Type the code : " ;
cin >> code;
cout << " Ammount of water : " ;
cin >> ammwater;
// get the code
switch (code)
{
             case 'H' :case 'h':
         cout << " The bill for account number " << acc<< " is for home use " << endl; 
         total = 5.0 + ( ammwater * 0.0005 )  ;
         cout << " The total payment would be $ " <<total<< ". Thank you" << endl;
          break;
          
              case 'C' : case 'c' :
              cout << " The bill for account number " << acc << "is for commercial use " << endl; 
              if (ammwater <= 4000000 )
              {
              cout << " The total payment would be $ " <<1000<< ". Thank you" << endl;
              }
              else 
              {
                   total = 1000 + (ammwater - 4000000);
             cout << " The total payment would be $ " << total << ". Thank you" << endl;
              }
          break;
            case 'I' : case 'i ' :
              {
                    cout << " The bill for account number " <<acc<< "is for industrial use" endl;
                     if (ammwater <= 4000000 )
              {
              cout << " The total payment would be $ " <<1000<< ". Thank you" << endl;
              }
                      else if ( 4000000 < ammwater < 10000000 ) 
                      { 
                          cout << " The total payment would be $ " <<2000<< ". Thank you" << endl;
                          else 
                          {
                                cout << " The total payment would be $ " << 3000 << ". Thank you" << endl;
                               }
              break;
                    default : 
                    
                         cout << " Syntax error, insert the right code. " << endl;    
                         return code;
                         }
                         
                         
                         return 0;
                         }

in line 39 , the program state the error : "overflow in implicit constant conversion "
correct for me please, thank you

Recommended Answers

All 5 Replies

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.

I tried to count lines to see which one is line 39, and I managed it

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

commented: Well spotted :) +4

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 .??

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:

else if ( 4000000 < ammwater < 10000000 )

Change it to:

else if ( 4000000 < ammwater && ammwater < 10000000 )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.