Hey all, here is the part of my code I need help with:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int acctNo, dayMin, nightMin, tmin;
double amtDue;
char serviceCode;
cout << "Account Number: " << flush;
cin >> acctNo;
What I'm wanting to do is, if someone inputs anything other than an int, output an Invalide Service Code error... here is the rest of my code.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int acctNo, dayMin, nightMin, tmin;
double amtDue;
char serviceCode;
cout << "Account Number: " << flush;
cin >> acctNo;
cout << "\nService Type: " << flush;
cin >> serviceCode;
cout << endl;
switch (serviceCode)
case 'r': case 'R':
{
cout << "Please input total minutes used: " << flush;
cin >> tmin;
amtDue = 10.00 + ( (tmin - 50) * 0.20 );
cout << endl << fixed << showpoint << setprecision(2);
cout << left << "Account: " << acctNo << endl << endl;
cout << setfill('.') << setw(25) << left << "Service Type: " << right << " Regular" << endl;
cout << setfill('.') << setw(25) << left << "Total Minutes Used " << right << " " << tmin << endl;
cout << setfill('.') << setw(25) << left << "Amount Due: " << right << " $" << amtDue << endl;
break;
case 'p': case 'P':
cout << "Total Day Time Minutes (6:00am-6:00pm): " << flush;
cin >> dayMin;
cout << "Total Night Time Minutes (6:00pm - 6:00am): " << flush;
cin >> nightMin;
amtDue = 25.00 + ((dayMin - 75) * 0.10) + ((nightMin - 100) * 0.05);
tmin = dayMin + nightMin;
cout << endl << fixed << showpoint << setprecision(2);
cout << left << "Account: " << acctNo << endl << endl;
cout << setfill('.') << setw(25) << left << "Service Type: " << right << " Premium" << endl;
cout << setfill('.') << setw(25) << left << "Total Minutes Used " << right << " " << tmin << endl;
cout << setfill('.') << setw(25) << left << "Amount Due: " << right << " $" << amtDue << endl;
break;
default: cout << "!! Invalid Service Code !!" << endl;
}
}
If you look at line 51 you'll see something as to what I want to do, though I'm not sure how to do it.
I tried if (acctNo != int) .... but it gave an error of unexpected int.
Thanks for any help! :mrgreen: