By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 1,743 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

When I call a function it won't print the information to screen.

P: 3
The Thankyou(); function will not print the variables fname and lname to screen.
the variables are extracted from a file.

Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. void thankYou();
  9. void showMenu();             
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.       const int SIZE = 60;
  14.       const int ADDRESS_SIZE =128;
  15.  
  16.       char status[SIZE];
  17.       char fname[SIZE];
  18.       char lname[SIZE];
  19.       char phoneNum[SIZE];
  20.  
  21.       char streetAdd[ADDRESS_SIZE];
  22.  
  23.       double transAmount;
  24.       char choice;
  25.       char again;
  26.       fstream people;
  27.       ofstream outFile;
  28.  
  29.         people.open ("C:\\potentials.txt");
  30.         if(!people)
  31.         {
  32.         cout <<" Error opening file.\n";
  33.         system("PAUSE");
  34.         return EXIT_FAILURE;
  35.         }
  36.         outFile.open("C:\\confirmed.txt");
  37.         if(!outFile)
  38.         {
  39.         cout <<" Error opening file confirmed.\n";
  40.         system("PAUSE");
  41.         return EXIT_FAILURE;              
  42.         }
  43.  
  44.         cout <<" Here are the Potential Customers:\n\n";
  45.  
  46.         people >> status;
  47.         people >> fname;
  48.         people >> lname;
  49.         people >> phoneNum;
  50.  
  51.         do
  52.         {                
  53.         if(!strcmp(status, "X"))
  54.         {
  55.         cout <<" "<< fname <<" "<< lname <<" "<< phoneNum 
  56.              << " Gets a 6.9% interest rate.\n";
  57.         }   
  58.         else
  59.         {
  60.         cout <<" "<< fname <<" "<< lname <<" "<< phoneNum 
  61.              << " Gets a 12.9% interest rate.\n";
  62.         } 
  63.  
  64.         showMenu();
  65.         cin >> choice;
  66.         cin.ignore();        
  67.             switch(choice)
  68.             {
  69.                case 'a':
  70.                case 'A':
  71.                {
  72.                cout <<" Ask for their Address and enter it here:\n";
  73.                cin.getline(streetAdd, ADDRESS_SIZE);
  74.                outFile << fname <<" "<< lname <<" "<< status <<" "
  75.                        << streetAdd <<" New customer" << endl;
  76.                system("cls");
  77.                thankYou();
  78.                break;
  79.                }
  80.  
  81.                case 't':
  82.                case 'T':
  83.                {
  84.                   if(!strcmp(status, "X"))
  85.                   {
  86.                   cout <<" Enter transfer amount.\n";
  87.                   cin >> transAmount;
  88.                   cin.ignore();
  89.                   cout <<" Ask for their Address and enter it here:\n";
  90.                   cin.getline(streetAdd, ADDRESS_SIZE);
  91.                   outFile << setprecision(2) << fixed;
  92.                   outFile << fname <<" "<< lname <<" "<< status 
  93.                           <<" "<< streetAdd <<" Transfer: $"<< transAmount << endl;
  94.                   system("cls");
  95.                   thankYou();
  96.                   break;
  97.                   } 
  98.                   else
  99.                   {
  100.                   cout <<" You can transfer up to $1000.00.\n";
  101.                   cout <<" Enter transfer amount: ";
  102.                   cin >> transAmount;
  103.                   cin.ignore();
  104.                   cout <<" Ask for their Address and enter it here:\n";
  105.                   cin.getline(streetAdd, ADDRESS_SIZE);
  106.                   outFile << fname <<" "<< lname <<" "<< status 
  107.                           <<" "<< streetAdd <<" Transfer: $"<< transAmount << endl;
  108.                   system("cls");
  109.                   thankYou();
  110.                   break;
  111.                   while(transAmount <= 0 || transAmount > 1000.00)
  112.                      {
  113.                      cout <<" Please enter an amount of $1000.00 "
  114.                           <<" or less.\n";
  115.                      cin >> transAmount;
  116.                      cout <<" Ask for their Address and enter it here:\n";
  117.                      cin.getline(streetAdd, ADDRESS_SIZE);
  118.                      outFile << fname <<" "<< lname <<" "<< status 
  119.                              <<" "<< streetAdd <<" Transfer: $"<< transAmount << endl;
  120.                      thankYou();
  121.                      cin.ignore();
  122.                      break;
  123.                      }            
  124.                   }            
  125.                }
  126.                case 'd':
  127.                case 'D':
  128.                {
  129.                   if(!strcmp(status, "X") == 1)
  130.                   {
  131.                   system("cls");
  132.                   cout <<" Call 1-800-ROBmeTO for special CASH back rewards.\n"
  133.                        <<" Don't miss out!\n"; 
  134.                        break;                 
  135.                   }
  136.                   else
  137.                   {
  138.                   system("cls");
  139.                   cout <<" Thank you for your time and have a nice day.\n";
  140.                   break;   
  141.                   }       
  142.                }     
  143.             }
  144.  
  145.         people >> status;
  146.         people >> fname;
  147.         people >> lname;
  148.         people >> phoneNum;
  149.  
  150.         cout <<"\n Press the enter key to get the next record.\n";
  151.  
  152.         cin.get(again);
  153.  
  154.         }while(!people.eof());
  155.         cout <<" That is all the data in the file!\n";
  156.         people.close(); 
  157.         outFile.close();
  158.  
  159.     system("PAUSE");
  160.     return EXIT_SUCCESS;
  161. }
  162.             void showMenu()
  163.             {                
  164.             cout <<" \n\t\tCredit Card Menu\n\n" 
  165.                  <<" Choose from the following menu.\n\n"
  166.                  <<" A --> If they (A)ccept the card\n"
  167.                  <<" T --> If they want to (T)ransfer a balance\n"
  168.                  <<" D --> If they (D)ecline the card\n"
  169.                  <<"\n Enter their choice\n"; 
  170.             }
  171.  
  172.         void thankYou()
  173.         { 
  174.             const int SIZE = 60;
  175.             char fname[SIZE];
  176.             char lname[SIZE];
  177.  
  178.             cout <<"\n\tCongradulations\n" << fname <<" "<< lname << endl;
  179.             cout <<" Your card will arrive by mail soon.\n";
  180.             cout <<" On behalf of RobMeBlind Credit Card Company\n";
  181.             cout <<" I would like to thank you for your order and\n";
  182.             cout <<" wish you happy shopping.\n";   
  183.         }
  184.  
Attached Files
File Type: zip teleGuide.zip (1.5 KB, 31 views)
Apr 1 '10 #1
Share this Question
Share on Google+
4 Replies


jkmyoung
Expert 100+
P: 2,057
You've declared NEW local variables in your function:
const int SIZE = 60;
char fname[SIZE];
char lname[SIZE];

You need to pass fname, lname as arguments to the function instead:
void thankYou(char[] fname, char[] lname)

and call the function
thankYou(fname, lname);
Apr 1 '10 #2

P: 3
Thank you for the reply, I also converted all variables to strings. It made it much easier.
Henry
Apr 2 '10 #3

P: 3
Thank you,
For someone like myself(wanting to program for a living) do you have any advise or could you point me in the direction I need to go. I was injured on the Job three years ago and must change careers. I love programming but I am unclear on the right direction.
Apr 2 '10 #4

Expert 100+
P: 464
I'm glad you got a solution here, but your next question is a better one for the software development section on this site. Programming is a broad field and you need to find what type of programming you like to do. I would say at first keep working through tutorials and try various types of programming and see what appeals to you. I would also say school would be a great decision for programming. There have been a lot of online discussions on schooling vs self learning, but personally I think both are needed. School for a good foundation and then self learning to pick up the various ins and outs of the language.
Apr 2 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.