proj 2 soln.cpp

proj 2 soln.cpp - / Water bill calculator #include...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Water bill calculator #include <iostream> #include <string> using namespace std; int main() { // Get and validate inital meter reading cout << "Initial meter reading: "; int initial; cin >> initial; cin.ignore(1000000, '\n'); if (initial < 0) { cout << "---\nThe initial meter reading must be nonnegative." << endl; return 1; } // Get and validate final meter reading cout << "Final meter reading: "; int final; cin >> final; cin.ignore(1000000, '\n'); if (final < initial) { cout << "---\nThe final reading must be at least as large as the initial reading." << endl; return 1; } // Get and validate customer name cout << "Customer name: "; string customer; getline(cin, customer); if (customer == "") { cout << "---\nYou must enter a customer name." << endl; return 1; } // Get and validate month cout << "Month number (1=Jan, 2=Feb, etc.): "; int month; cin >> month; cin.ignore(1000000, '\n'); if (month < 1 || month > 12) { cout << "---\nThe month number must be in the range 1 through 12." << endl; return 1; } // Bill thresholds and rates
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2011 for the course CS 31 taught by Professor Melkanoff during the Spring '00 term at UCLA.

Page1 / 3

proj 2 soln.cpp - / Water bill calculator #include...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online