We are doing an assignment that reads from a file on the hard drive, asks for user input and then writes it to a different file on the hard drive. We have to use three different functions, besides the main, and cannot use global variables.
I cannot seem to get all of the information I need to print to my output file. Everything prints in the file except the address and tamount. The tamount prints, just not what is input by the user.
Thanks in advance for your help.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
//Function Prototypes
void accept (char letter);
void transfer (char letter);
void decline (char letter);
int menu ();
int main()
{
const int SIZE = 100; //Length of line
char first[SIZE], last[SIZE], phone[SIZE], status, address[SIZE];
int X, pref, tamount;
ifstream inputFile; //File Stream Object
inputFile.open ("c:\\potentials.txt", ios::in); //Open File
if (inputFile.fail()) //Error Opening File
{
cout << "Error opening file. The file could not be found.\n";
cout <<""<<endl;
system ("PAUSE");
return EXIT_FAILURE;
}
ofstream outputFile; //File to output to
outputFile.open ("c:\\confirmed.txt", ios::out);
if (outputFile.fail()) //Error Opening File
{
cout << "Error opening file. The file could not be found.\n";
cout <<""<<endl;
system ("PAUSE");
return EXIT_FAILURE;
}
do
{
system ("CLS");
cout << "Customer Call list:" << endl;
cout << " " << endl;
// Determine status
inputFile >> status;
if (status == 'X' || status == 'x')
{
cout << "Preferred Customer offer a 7.9% interest rate!" << endl;
pref=0;
}
else
{
cout << "Offer a 12.9% interest rate!" << endl;
pref=1;
}
// Get name
inputFile >> first >> last;
cout << first << " " << last << endl;
// Get phone number
inputFile >> phone;
cout << phone << endl;
cout << "" << endl;
cout << "" << endl;
cout << "" << endl;
char letter;
letter = menu ();
switch (letter)
{
case 'A': accept ('A');
cin.getline (address, SIZE);
outputFile << first << " " << last << " " << status << " " << address << " " << "New Card" << endl;
break;
case 'a': accept ('a');
cin.getline (address, SIZE);
outputFile << first << " " << last << " " << status << " " << address << " " << "New Card" << endl;
break;
case 'T': transfer ('T');
cin.getline (address, SIZE);
outputFile << first << " " << last << " " << status << " " << address << " " << "Transfer: "<< tamount << endl;
break;
case 't': transfer ('t');
cin.getline (address, SIZE);
outputFile << first << " " << last << " " << status << " " << address << " " << "Transfer: "<< tamount << endl;
break;
case 'D': decline ('D');
cin.ignore ();
break;
case 'd': decline ('d');
cin.ignore ();
break;
}
} while (1);
return 0;
}
//******************************************************************************
// Definition of function menu. *
// Displays the menu and asks user to select an option. *
//******************************************************************************
int menu ()
{
char letter;
cout << "Please press the corresponding letter for the option you would like:" << endl;
cout << "" << endl;
cout << "A -- Accept the credit card" << endl;
cout << "T -- Transfer a balance" << endl;
cout << "D -- Decline the card" << endl;
cout << "" << endl;
cout << "Please enter your choice:" << endl;
cin >> letter;
cout << "" << endl;
while ((letter == 'T' || letter == 't') && (letter =='A' || letter =='a') && (letter == 'D' || letter == 'd'))
{
cout << "Invalid Selection. Enter A, T or D:" << endl;
cin >> letter;
}
return letter;
}
//******************************************************************************
// Definition for letter choice A. *
// This function is for customers who choose to accept the card offer. *
//******************************************************************************
void accept (char letter)
{
const int SIZE = 100; //Length of line
char address[SIZE];
cout << "Ask the customer for their address and enter it here: " << endl;
cin.ignore ();
cin.getline (address, SIZE);
system ("CLS");
cout << "Tell The customer, ' Thank you for your order today, expect" << endl;
cout << " your card to arrive in the mail soon, happy charging.'" << endl;
cout << " " << endl;
cout << "Press ENTER key for next customer." << endl;
}
//******************************************************************************
// Definition for letter choice T. *
// This function is for customers who choose to accept the card offer. *
//******************************************************************************
void transfer (char letter)
{
const int SIZE = 100; //Length of line
char address[SIZE], status, pfc, y, Y;
int tamount;
cout << "Is this a Preferred Customer?" << endl;
cin >> pfc;
if (pfc == 'y' || pfc == 'Y')
{
cout << "There is no transfer limit. How much would you like to transfer?" << endl;
cin >> tamount;
cout << "" << endl;
cout << "Ask the customer for their address and enter it here: " << endl;
cin.ignore ();
cin.getline (address, SIZE);
cout << "" << endl;
cout << "Tell The customer, ' Thank you for your order today, expect";
cout << " your card to arrive in the mail soon, happy charging.'" << endl;
cout << " " << endl;
cout << "Press ENTER key for next customer." << endl;
}
else
{
cout << "There is a transfer limit of $1000. How much would you like to transfer?" << endl;
cin >> tamount;
if (tamount <=1000)
{
cout << "" << endl;
cout << "Ask the customer for their address and enter it here: " << endl;
cin.ignore ();
cin.getline (address, SIZE);
system ("CLS");
cout << "Tell The customer, ' Thank you for your order today, expect";
cout << " your card to arrive in the mail soon, happy charging.'" << endl;
cout << " " << endl;
cout << "Press ENTER key for next customer." << endl;
}
if (tamount >1000)
{
cout << "You have entered an amount over the transfer limit, please enter an amount up to $1000." << endl;
cin >> tamount;
cout <<""<<endl;
cout << "Ask the customer for their address and enter it here: " << endl;
cin.ignore ();
cin.getline (address, SIZE);
system ("CLS");
cout << "Tell The customer, ' Thank you for your order today, expect";
cout << " your card to arrive in the mail soon, happy charging.'" << endl;
cout << " " << endl;
cout << "Press ENTER key for next customer." << endl;
}
}
}
//******************************************************************************
// Definition for letter choice D. *
// This function is for customers who choose to accept the card offer. *
//******************************************************************************
void decline (char letter)
{
char status, pfc; // <- A local variable, uninitialized
cout << "Is this a Preferred Customer?" << endl;
cin >> pfc;
cout << "" << endl;
system ("CLS");
if (pfc == 'Y' || pfc == 'y')
{
cin.ignore ();
cout << "Tell the customer, 'There are amazing cash back rewards available to you! Don't miss out on this opportunity!'" << endl;
cout << " " << endl;
cout << "Please call 888-555-1234 for a deal you won't be able to pass on!" << endl;
cout << "" << endl;
cout << "Press ENTER key for next customer." << endl;
}
else
{
cin.ignore ();
cout << "Thank you for your time and consideration. Goodbye." << endl;
cout << " " << endl;
cout << "Press any key for next customer." << endl;
}
}