| | |
if staement
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 101
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
//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
•
•
Join Date: Aug 2008
Posts: 206
Reputation:
Solved Threads: 31
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.
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.
•
•
Join Date: Oct 2008
Posts: 101
Reputation:
Solved Threads: 0
sorry i DONT' KNOW WHAT YOU MEAN, you mean it was not my mistake right, and how to sove this problem .??
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
More about it here http://home.att.net/~jackklein/c/inttypes.html
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
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:
Change it to:
C++ Syntax (Toggle Plain Text)
else if ( 4000000 < ammwater < 10000000 )
Change it to:
C++ Syntax (Toggle Plain Text)
else if ( 4000000 < ammwater && ammwater < 10000000 )
![]() |
Similar Threads
- ATM program part 2 (Python)
- readin from differnt records(.dbf) at atime (Visual Basic 4 / 5 / 6)
- Fibonacci Sequence (VB.NET)
- Exit to Dos in a C program from a Switch staement (C++)
- a beginner needs help (C++)
- ATI vs. ATI question. (Monitors, Displays and Video Cards)
Other Threads in the C++ Forum
- Previous Thread: Understanding Arrays
- Next Thread: Some sort of logical error
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






