Posted by: himalayandude November 20, 2006
C Programing question
Login in to Rate this Post:     0       ?        
// Program: // Author: *********** // Date: Nov 20 2006 // Assignment: // Purpose: // // Input: // Output: : // Related // Files: // Functions: // #include using namespace std; const double rServiceCost = 10.00; const double rPerMinuteCharge = .20; const double pServiceCost = 25.00; const double pDayPerMinuteCharge = .10; const double pNightPerMinuteCharge = .05; int main() { int minutes; int dayMinutes; int nightMinutes; char serviceCode; int accountNumber; double amountDue; cout << "Enter an account number: "; cin >> accountNumber; cout << endl; cout << "Enter a service code: R or r (regular), P or p (premium): "; cin >> serviceCode; cout << endl; switch (serviceCode) { case 'r': case 'R': cout << "Enter the number of minutes used: "; cin >> minutes; cout << endl; if (minutes <= 50) amountDue = rServiceCost; else amountDue = rServiceCost + ((minutes - 50) * rPerMinuteCharge); cout << "Account number = " << accountNumber << endl; cout << "Type of service: " << serviceCode << endl; cout << "Number of minutes used: " << minutes << endl; cout << "Amount Due = $" << amountDue << endl; break; case 'p': case 'P': cout << "Enter the number of day minutes used: "; cin >> dayMinutes; cout << endl; cout << "Enter the number of night minutes used: "; cin >> nightMinutes; cout << endl; if (dayMinutes <= 75) amountDue = pServiceCost; else amountDue = pServiceCost + ((minutes - 75) * pDayPerMinuteCharge); cout << "Account number = " << accountNumber << endl; cout << "Type of service: " << serviceCode << endl; cout << "Number of minutes used: " << minutes << endl; cout << "Amount Due = $" << amountDue << endl; if (nightMinutes <= 100) amountDue = pServiceCost; else amountDue = pServiceCost + ((minutes - 100) * pNightPerMinuteCharge); cout << "Account number = " << accountNumber << endl; cout << "Type of service: " << serviceCode << endl; cout << "Number of minutes used: " << minutes << endl; cout << "Amount Due = $" << amountDue << endl; break; default: cout << "Invalid service code" << endl; } return 0; }

I just copied what you had and named it test.cpp and compiled using g++ test.cpp . It runs fine.......

Read Full Discussion Thread for this article