I need to redo this program before finals... I need to correct some things to get extra credit. It opens a file named "credit.txt" . In the code I placed it in the d: drive. So if you want to run it and make sure it works... that's where I've located it according to the code.
Long story short... I need this program to gather the information about people and then take the data and write it to another file.
My problem is that I'm having problems getting information from non-preferred customers.
I've also attached the original assignment so you can see exactly what I'm talking about. Don't worry, I've already gotten a 'C' on this, but I need some bonus points to help on the final. Every little bit helps.
Any pushes in the right direction would be greatly appreciated.
Code:
//This program is a telemarketing program that assists
//the telemarketer by determining interest rate for each customer based on
//preferred status and will collect data if they accept card
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
fstream inFile;
string first, last, phone, status;
string address;
string city;
string zip;
int choice;
double transfer;
bool error;
do
{
inFile.open("d:\\credit.txt", ios::in); //do not have a: drive
//error reporting if file is not located or cannot be opened.
if (inFile.fail())
{
cout<<"ERROR: Cannot open the file.\n";
inFile.open("d:\\credit.txt", ios::out); //creates file
error = true;
}
else
{
error = false;
}
}while(error);
cout<<"File opened successfully."<<"\n\n";
cout<<"Reading Data from File."<<"\n\n";
cout<<setfill('-')<<setw(80)<<"-"<<endl;
while(!inFile.eof())
{
inFile >> status;
inFile >> first;
inFile >> last;
inFile >> phone;
string temp = "X";
if (!status.compare(temp)) //returns non-zero if strings are not equal
{
cout<<first<<" "<<last<<" "<<phone<<"\n\n";
cout<<"Preferred Customer: 7.9% APR\n";
cout<<"There is not transfer limiit for this customer";
cout<<"\n\nCredit Card Menu\n";
cout<<"1. Accept Card\n";
cout<<"2. Accept and Transfer Balance\n";
cout<<"3. Decline Card\n";
cout<<"\n\nEnter Choice: ";
//this just makes sure the user doesn't enter crap
bool flag;
string temp;
do
{
if(!(cin >> choice))
{
cin.clear();
cout << "\ninvalid input. ";
getline(cin, temp);
cout << "You entered " << temp << ".\n";
cout << "Please try again.\n";
flag = true;
}
else
{
flag = false;
}
}while(flag);
cin.get(); //clears the buffer
cout<<"\n\n";
switch (choice)
{
case 1:
cout<<"Please collect address information\n\n";
cout<<"Street Address: ";
getline(cin, address, '\n'); //cin>>address;
cout<<"\nCity: ";
getline(cin, city, '\n'); //cin>>city;
cout<<"\nZip Code: ";
getline(cin, zip, '\n'); //cin>>zip;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
case 2:
cout <<"Please collect address information\n\n";
cout<<"Street Address: ";
getline(cin, address, '\n'); //cin>>address;
cout<<"\nCity: ";
getline(cin, address, '\n'); //cin>>city;
cout<<"\nZip Code: ";
getline(cin, zip, '\n'); //cin>>zip;
cout<<"\nHow much would they like to transfer? ";
bool flag2;
do
{
string temp2;
if(!(cin >> transfer))
{
cin.clear();
cout << "\ninvalid input. ";
getline(cin, temp2);
cout << "You entered " << temp2 << ".\n";
cout << "Please try again\n";
flag2 = true;
}
else
{
flag2 = false;
}
}
while(flag2);
cin.get(); //clears the buffer
//cin >> transfer;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
case 3:
cout<<setfill('-')<<setw(80)<<"-"<<endl;
cout<<"Preferred Customers can recieve cash-back rewards\n";
cout<<"if they change their minds. They can call 1-800-555-5555";
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
}
}
else
{
cout<<first<<" "<<last<<" "<<phone<<"\n\n";
cout << "\n\nNot a preferred customer\n";
cout << "Higher interest rate applies";
cout<<"Non-Preferred Rate: 12.9% APR\n";
cout<<"\n\nCredit Card Menu\n";
cout<<"1. Accept Card\n";
cout<<"2. Accept and Transfer Balance\n";
cout<<"3. Decline Card\n";
cout<<"\n\nEnter Choice: ";
//this just makes sure the user doesn't enter crap
bool flag;
string temp;
do
{
if(!(cin >> choice))
{
cin.clear();
cout << "\ninvalid input. ";
getline(cin, temp);
cout << "You entered " << temp << ".\n";
cout << "Please try again.\n";
flag = true;
}
else
{
flag = false;
}
}while(flag);
cin.get(); //clears the buffer
cout<<"\n\n";
switch (choice)
{
case 1:
cout<<"Please collect address information\n\n";
cout<<"Street Address: ";
getline(cin, address, '\n'); //cin>>address;
cout<<"\nCity: ";
getline(cin, city, '\n'); //cin>>city;
cout<<"\nZip Code: ";
getline(cin, zip, '\n'); //cin>>zip;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
case 2:
cout <<"Please collect address information\n\n";
cout<<"Street Address: ";
getline(cin, address, '\n'); //cin>>address;
cout<<"\nCity: ";
getline(cin, address, '\n'); //cin>>city;
cout<<"\nZip Code: ";
getline(cin, zip, '\n'); //cin>>zip;
cout<<"\nHow much would they like to transfer? ";
bool flag2;
do
{
string temp2;
if(!(cin >> transfer))
{
cin.clear();
cout << "\ninvalid input. ";
getline(cin, temp2);
cout << "You entered " << temp2 << ".\n";
cout << "Please try again\n";
flag2 = true;
}
else
{
flag2 = false;
}
}
while(flag2);
cin.get(); //clears the buffer
//cin >> transfer;
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
case 3:
cout<<setfill('-')<<setw(80)<<"-"<<endl;
cout<<"Preferred Customers can recieve cash-back rewards\n";
cout<<"if they change their minds. They can call 1-800-555-5555";
cout<<setfill('-')<<setw(80)<<"-"<<endl;
break;
system("PAUSE");
cout << endl;
}
}
status.erase();
first.erase();
last.erase();
phone.erase();
}
cout<<setfill('-')<<setw(80)<<"-"<<endl;
//Close the file
inFile.close();
cout<<"\nDone.\n\n";
return 0;
}