I am inputing from a text file, displaying it on the screen, displaying the menus and the choosing from there. It will repeat the menu, but, how to do I get it to read the next line in my input file and display it to the screen before repeating the menu?
Here's what I have.
#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;
int X, pref;
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;
}
// Determine status
inputFile >> status;
if (status == 'X' || status == 'x')
{
cout << "Preferred -- 7.9%" << endl;
pref=0;
}
else
{
cout << "12.9%" << endl;
pref=1;
}
// Get name
inputFile >> first >> last;
cout << first << " " << last << endl;
// Get phone number
inputFile >> phone;
cout << phone << endl;
cout << "" << endl;
char letter;
do
{
letter = menu ();
switch (letter)
{
case 'A': accept ('A');
break;
case 'a': accept ('a');
break;
case 'T': transfer ('T');
break;
case 't': transfer ('t');
break;
case 'D': decline ('D');
break;
case 'd': decline ('d');
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 >> address;
cout << "" << endl;
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;
}
}
//******************************************************************************
// 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;
float tamount;
cout << "Is this a Preferred Customer?" << endl;
cin >> pfc;
while(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 >> address;
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;
}
if (pfc !='y' || pfc !='Y')
{
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 >> address;
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;
}
else if (tamount >1000)
{
cout << "You have entered an amount over the transfer limit, please try again." << endl;
cin >> tamount;
cout <<""<<endl;
}
}
//******************************************************************************
// Definition for letter choice D. *
// This function is for customers who choose to accept the card offer. *
//******************************************************************************
void decline (char letter)
{
// <- A local variable, uninitialized
char status, pfc; // <- A local variable, uninitialized
cout << "Is this a Preferred Customer?" << endl;
cin >> pfc;
cout << "" << endl;
if (pfc == 'Y' || pfc == 'y')
{
cout << "Tell the customer, 'There are amazing cash back rewards available to you!" << endl;
cout << "Please call 888-555-1234 for a deal you won't be able to pass on!" << endl;
cout << "" << endl;
}
else
{
cout << "Thank you for your time and consideration. Goodbye." << endl;
cout << "" << endl;
}
}