Reading data from a file...

Data in the file contains the following:
X Joe Scholtz 437-4798
A Tim Wade 768-7658
X Sara Jobs 326-7857
! Jaynce Bee 354-8678

I need to read from the file the status(which would be X,A or!), name and phone number. Customer has a preferred status if the field contains an X..if anything else, they are not preferred.

Display the name, phone number and available interest rate for that customer(preferred customer gets 7.9%, everyone else, 12.9%).

I think she wants me to display 1 customer at a time along with interest rate...but I'm having trouble displaying the phone number. Any clues/advice? This is what I have so far:

#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char *argv[])
{
ifstream inFile;

char status, fname[8], lname[10];
int phone;

inFile.open("C:\\DOCS\\potentials.txt");

inFile >> status >> fname >> lname >> phone;
cout << status << fname << lname << phone;


system("PAUSE");
return EXIT_SUCCESS;
}
closed account (Lv0f92yv)
What is your output after running this program?

Also, as a side note, try not to get in the habit of using system("PAUSE") to 'pause' your programs. This is 'system dependent' among other things. (Though for a homework assignment it probably isn't a big deal).

Try getchar();. It causes the program to wait for the user to press a key (enter will do) before continuing.
XJoeScholtz437 is the output I get. Guess I could use string for fname, lname and phone. This is the rest of the assignment, for which I'm thinking a "do while" loop would work well. Any thoughts?

• Read a customer status, name and phone number from a file called C://potentials.txt

o A customer has a preferred status if the field contains an ‘X’. If it contains anything else, they are not preferred.

• Display the name, phone number and the available interest rate for that customer so that the telemarketer can read it, call the customer and offer them a credit card

o Preferred customers get 7.9%, everybody else gets 12.9%

• Display a menu offering the following options:

o Enter ‘A’ to Accept the card
For this option –
 Ask for an address to send the card to
 Accept the address
 Print a thank you message for telemarketer to read telling the customer to expect the card soon.

o Enter ‘T’ to accept and Transfer a balance
For this option-
 If preferred – tell them there is no transfer limit
• Accept any dollar amount entered
 If not preferred – tell them they can transfer up to $1000
• Accept any dollar amount entered as long as it isn’t greater than 1000 (keep asking until you get something less than 1000)
 Ask for an address to send the card to
 Accept the address
 Print thank you message for telemarketer to read telling the customer to expect the card soon, happy charging

o Enter ‘D’ to Decline the card
For this option
 If preferred – tempt them with cash back rewards and give them a special phone number to call for a better card
 If not preferred – tell them thanks anyhow

• Write the results to a file called C://confirmed.txt

o This file should contain the following:
 Name
 Address
 Status flag (X or whatever)
 If the account is new (A) or transfer (T)
 Any dollar amount they may be transferring.

If the customer declines, they should not appear in the confirmed file

Requirements:

• You must implement at least three functions other than the main function.
• You may not use global variables!
Is there a Q option for quitting? Do while sounds good. And one of your three functions outside of main could be void displayMenu(){/*cout statements for menu*/}
Last edited on
There is no Q option for quitting. Just this when done:

• Write the results to a file called C://confirmed.txt

o This file should contain the following:
 Name
 Address
 Status flag (X or whatever)
 If the account is new (A) or transfer (T)
 Any dollar amount they may be transferring.

If the customer declines, they should not appear in the confirmed file

void displayMenu(){/*cout statements for menu*/} will definitely be used as one function.
Topic archived. No new replies allowed.