Menu driven code

This is a discussion on Menu driven code within the C++ Programming forums, part of the General Programming Boards category; Need help reading data from a file that looks like this: Code: X Joe Scholtz 437-4798 A Tim Wade 768-7658 ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    38

    Menu driven code

    Need help reading data from a file that looks like this:
    Code:
    X Joe Scholtz 437-4798
    A Tim Wade 768-7658
    X Sara Jobs 326-7857
    ! Jaynce Bee 354-8678
    This file may be longer than this or shorter (it's an example). I have to create a menu driven code that will open a file that looks like that and give me menu options for each name. It's a telemarketer's program that will determine what interest rate will be given to each customer based on if they are preferred or not (That's the X, A, ! characters you see in the file above).

    Trying to make a telemarketer's program that will first open a file in this format: status code (one letter/symbol for approved, preferred, not, etc.), first name, last name, phone number (with dashes).

    From there the program will display the name, phone number, status (preferred/not preferred), and what there available APR is based on if they are preferred or not.

    Under this info will be a menu... press 1 to accept the card, 2 to transfer balance from another card, or 3 to decline card.

    Anyway, need help creating these menus.
    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>
    using namespace std;
    
    int main()
    {
    	
    
    	ifstream inFile;
    	
    	
    	char first[10], last[10], status [1], phone [8];
    char street [25], city [15], zip [5];
    
    
    
    	inFile.open("a:\\credit.txt");
    	
    	//error reporting if file is not located or cannot be opened.
    	if (inFile.fail())
    	{
    		cout<<"ERROR:  Cannot open the file.\n";
    		return 0;
    	}
    	
    	cout<<"File opened successfully."<<"\n\n";
    	cout<<"Reading Data from File."<<"\n\n";
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    	//Inputs first line of data
    	inFile>>status;
    	inFile>>first;
    	inFile>>last;
    	inFile>>phone;
    
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    
    //Close the file
    	inFile.close();
    	cout<<"\nDone.\n\n";
    	return 0;
    }
    This system must also allow for input of address info if the people accept the card. Then this file must write to a file saving the information.

    Thanks for any help

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    The first thing you want to check is if the code you currently have is working like you want it to. Print out the strings you are reading from the file to make sure everything is working as expected.

    Code:
    status [1]
    status is declared as an array which can only hold 1 character. If you mean for this to be a C style string, then you need room for a null terminating character as well. If you just want to hold a single char, then why not declare it just as:
    Code:
    char status;
    Code:
    inFile>>status;
    inFile>>first;
    inFile>>last;
    inFile>>phone;
    This is dangerous. You have no way of knowing how many characters are being read into these arrays, so you have to way of preventing buffer overflows. One option is to use std::strings instead of arrays.

    It looks like you need to mess around with your code for awhile to get a better feel for what's going on.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    You're right, but this is suppose to be a very simple list of names and status. We haven't used std::string yet. So I don't want to use something I don't fully understand just yet.

    So far:
    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>
    using namespace std;
    
    int main()
    {
    	
    
    	ifstream inFile;
    	
    	
    	char first[10], last[10], status [1], phone [8];
    	char street [25], city [15], zip [5];
    	char choice[1];
    	double transfer;
    
    
    	inFile.open("d:\\credit.txt"); //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";
    		return 0;
    	}
    	
    	cout<<"File opened successfully."<<"\n\n";
    	cout<<"Reading Data from File."<<"\n\n";
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    	//Inputs first line of data
    	inFile>>status;
    	inFile>>first;
    	inFile>>last;
    	inFile>>phone;
    	
    	while (char status 'X')
    	{
    		cout<<first<<" "<<last<<" "<<phone<<"\n\n";
    		cout<<"Preferred Customer:  7.9% APR\n\n";
    		cout<<"\t\tCredit Card Menu\n\n";
    		cout<<"A. Accept Card\n";
    		cout<<"T. Accept and Transfer Balance\n";
    		cout<<"D. Decline Card\n";
    		cout<<"\n\nEnter Choice: ";
    		cin>>choice;
    		cout<<"\n\n\n";
    		switch (choice)
    		{
    		case 'a':
    		case 'A': cout<<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			cin>>street;
    			cout<<"\nCity:  ";
    			cin>>city;
    			cout<<"\nZip Code:  ";
    			cin>>zip;
    			break;
    		case 't':
    		case 'T': cout <<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			cin>>street;
    			cout<<"\nCity:  ";
    			cin>>city;
    			cout<<"\nZip Code:  ";
    			cin>>zip;
    			cout<<"How much would they like to transfer? ";
    			cin>>transfer;
    			break;
    		case 'd':
    		case 'D': 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;
    
    
    
    //Close the file
    	inFile.close();
    	cout<<"\nDone.\n\n";
    	return 0;
    }
    BTW, I'm using 'A', 'D', and 'T' as my options as per the assignment (I'd much rather use 1, 2, 3).
    Last edited by liquidcourage1; 04-02-2006 at 12:53 PM. Reason: note

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    New code so far:
    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>
    
    using namespace std;
    
    int main()
    {
    	
    
    	ifstream inFile;
    	ofstream outFile;
    	
    	char first[10], last[10], status [1], phone [8];
    	char street[40], city [15], zip [5];
    	char choice;
    	double transfer;
    
    
    	inFile.open("d:\\credit.txt"); //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";
    		return 0;
    	}
    	
    	cout<<"File opened successfully."<<"\n\n";
    	cout<<"Reading Data from File."<<"\n\n";
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    	
    	//Inputs first line of data
    	inFile>>status;
    	inFile>>first;
    	inFile>>last;
    	inFile>>phone;
    
    	
    	
    	while (char status='X')
    	{
    		cout<<first<<" "<<last<<" "<<phone<<"\n\n";
    		cout<<"Preferred Customer:  7.9% APR\n\n";
    		cout<<"There is not transfer limiit for this customer";
    		cout<<"\t\tCredit Card Menu\n\n";
    		cout<<"A. Accept Card\n";
    		cout<<"T. Accept and Transfer Balance\n";
    		cout<<"D. Decline Card\n";
    		cout<<"\n\nEnter Choice: ";
    		cin>>choice;
    		cout<<"\n\n\n";
    		switch (choice)
    		{
    		case 'a':
    		case 'A':
    			cout<<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			cin.getline (street,40);
    			cout<<"\nCity:  ";
    			cin>>city;
    			cout<<"\nZip Code:  ";
    			cin>>zip;
    			cout<<setfill('-')<<setw(80)<<"-"<<endl;
    			break;
    		case 't':
    		case 'T':
    			cout <<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			cin.getline (street,40);
    			cout<<"\nCity:  ";
    			cin>>city;
    			cout<<"\nZip Code:  ";
    			cin>>zip;
    			cout<<"\nHow much would they like to transfer? ";
    			cin>>transfer;
    			cout<<setfill('-')<<setw(80)<<"-"<<endl;
    			break;
    		case 'd':
    		case 'D': 
    			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;
    		
    	}
    
    
    
    	}
    	
    
    
    
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    
    //Close the file
    	inFile.close();
    	cout<<"\nDone.\n\n";
    	return 0;
    }
    Need a push in the right direction, though. I'm looping only on the first line of data. I don't know how to get my loop to go to the next line (name) and start all over again.

    Then when this part is done, I need to be able to write it to a file.

    Thanks

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    36
    You need a sentinal controlled loop.

    I assume that '!' is the last person sentinal.

    Pseudo Code

    Code:
    // cin first file strings
    
    // conditional process first
    while(flag!=status)
    {
         // cin file strings
    
         // conditional process people one at a time(switch)
    
         if(status = !)
         {
              flag=status;
         }
    }
    The major problem with this is that the last person in the file cant be a perferred customer.
    Last edited by jlharrison; 04-02-2006 at 05:39 PM.

  6. #6
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    Quote Originally Posted by jlharrison
    The major problem with this is that the last person in the file cant be a perferred customer.
    I don't think that's a problem with the way this assignment is worded.

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    I've now included:
    Code:
    while(!inFile.eof())
    {
    }
    but I don't know if the rest of the code is embedded within this?

  8. #8
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    CHANGED


    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()
    {
    	
    
    	ifstream inFile;
    	ofstream outFile;
    	
    	string first, last, phone;
    	string address;
    	string city ;
    	string zip;
    	char choice,status;
    	double transfer;
    
    
    	inFile.open("d:\\credit.txt"); //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";
    		return 0;
    	}
    	
    	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;
    	
    	if (status='X')
    	{
    
    	
    		cout<<first<<" "<<last<<" "<<phone<<"\n\n";
    		cout<<"Preferred Customer:  7.9% APR\n\n";
    		cout<<"There is not transfer limiit for this customer";
    		cout<<"\t\tCredit Card Menu\n\n";
    		cout<<"A. Accept Card\n";
    		cout<<"T. Accept and Transfer Balance\n";
    		cout<<"D. Decline Card\n";
    		cout<<"\n\nEnter Choice: ";
    		cin>>choice;
    		cout<<"\n\n\n";
    		switch (choice)
    		{
    		case 'a':
    		case 'A':
    			cout<<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			getline(cin,address);
    			cout<<"\nCity:  ";
    			getline (cin,city);
    			cout<<"\nZip Code:  ";
    			getline(cin,zip);
    			cout<<setfill('-')<<setw(80)<<"-"<<endl;
    			break;
    		case 't':
    		case 'T':
    			cout<<"Please collect address information\n\n";
    			cout<<"Street Address:  ";
    			getline(cin,address);
    			cout<<"\nCity:  ";
    			getline (cin,city);
    			cout<<"\nZip Code:  ";
    			getline(cin,zip);
    			cout<<"\nHow much would they like to transfer? ";
    			cin>>transfer;
    			cout<<setfill('-')<<setw(80)<<"-"<<endl;
    			break;
    		case 'd':
    		case 'D': 
    			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;
    		}
    		
    	}
    
    	}
    
    	
    
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    
    
    //Close the file
    	inFile.close();
    	cout<<"\nDone.\n\n";
    	return 0;
    }
    Last edited by liquidcourage1; 04-02-2006 at 06:18 PM.

  9. #9
    Moderately Rabid Decrypt's Avatar
    Join Date
    Feb 2005
    Location
    Milwaukee, WI, USA
    Posts
    300
    It's not skipping over the city and ZIP so much as assigning the wrong values to the variables. cin reads to the first whitespace, then stops. So, if for your address, you enter 200 Whereami St., this is what happens:
    Code:
    cin >> address; //address now = to 200
    cin >> city; // city now = Whereami
    cin >> zip; //zip now = St.
    cin leaves the whitespace and everything after it in the input stream, where it is picked up by the next call to cin. To get the whole thing into address, use getline.
    There is a difference between tedious and difficult.

  10. #10
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    Quote Originally Posted by Decrypt
    It's not skipping over the city and ZIP so much as assigning the wrong values to the variables. cin reads to the first whitespace, then stops. So, if for your address, you enter 200 Whereami St., this is what happens:
    Code:
    cin >> address; //address now = to 200
    cin >> city; // city now = Whereami
    cin >> zip; //zip now = St.
    cin leaves the whitespace and everything after it in the input stream, where it is picked up by the next call to cin. To get the whole thing into address, use getline.
    Awesome. That works pretty well. The little tutorial page you included saved my butt. However, my program terminates after I enter the information. I need it to go to the next line in the program and go through it until it gets to the last line... then terminate.

    Thanks (I edited my code above to save space)

  11. #11
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    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;
    	string address;
    	string city;
    	string zip;
    	int choice;
    	char status;
    	double transfer;
    
    	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("credit.dat", ios::out);
    	}
    	
    	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;
    		
    		if (status='X')
    		{
    			cout<<first<<" "<<last<<" "<<phone<<"\n\n";
    			cout<<"Preferred Customer:  7.9% APR\n\n";
    			cout<<"There is no transfer limit 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\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); //cin>>address;
    					cout<<"\nCity:  ";
    					getline(cin, city); //cin>>city;
    					cout<<"\nZip Code:  ";
    					getline(cin, zip); //cin>>zip;
    					cout<<setfill('-')<<setw(80)<<"-"<<endl;
    					break;
    		
    				case 2:
    					cout <<"Please collect address information\n\n";
    					cout<<"Street Address:  ";
    					getline(cin, address); //cin>>address;
    					cout<<"\nCity:  ";
    					getline(cin, address); //cin>>city;
    					cout<<"\nZip Code:  ";
    					getline(cin, zip); //cin>>zip;
    					cout<<"\nHow much would they like to transfer? ";
                                            //this just makes sure the user doesn't enter crap
    
    			bool flag2;
               
    			do
    			{
    				string temp2;
    				if(!(cin >> transfer))
    				{
    					cin.clear();
    					cout << "\ninvalid input. ";
    					getline(cin, temp2);
    					cout << "You entered " << temp2 << ".\n\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;
    			}
    			
    		}
    	}
    
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    
    	//Close the file
    	inFile.close();
    	cout<<"\nDone.\n\n";
    
    	return 0;
    }
    My code isn't choosing preferred/non-preferred differently. Can somebody help me out?

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> if (status='X')
    Remember the difference between assignment and an equality test.

    >> while (!inFile.eof())
    It would be better to make this while (inFile>>status) or you will likely run the loop one time too many.

  13. #13
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    Ok. That makes sense. I appreciate it.

  14. #14
    Registered User
    Join Date
    Feb 2006
    Posts
    38
    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;
    }
    Attached Files Attached Files
    Last edited by liquidcourage1; 04-23-2006 at 06:28 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  2. menu driven interface
    By weegi in forum C Programming
    Replies: 4
    Last Post: 04-17-2004, 04:08 PM
  3. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Windows Programming
    Replies: 0
    Last Post: 10-14-2002, 01:29 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21