Thread: Set function not printing

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Set function not printing

    Hi I am creating an invoice class to print the results of a virtual shop invoice.
    The program as far as the compiler is concerned is correct, but I am getting no output from the functions when I call them. What silly error am I making? here is the code:

    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    using std::cin;
    
    #include <string>
    
    using std::string;
    
    class Invoice
    {
    public:
        Invoice( string, string, int, int )
        {
           string pnum;
           string pdisc;
           int initquan;
           int initppi;
           
           pNumber = pnum;
           pDisc = pdisc;
           quant = initquan;
           ppi = initppi;
        }
        
        // getter functions
        string getPrtNum()
        {
           return pNumber;
        }
        
        string getPrtDisc()
        {
           return pDisc;
        }
        
        int getQuant()
        {
           return quant;
        }
        
        int getPpi()
        {
           return ppi;
        }
        
        int getInvoiceAmount()
        {
           return quant * ppi;
        }
        
        // setter functions
        string setPrtNum ( string pn )
        {
           pn = "12121\n12141\n14215\n14214";
           pNumber = pn;
           return pn;
        }
        
        string setPrtDisc ( string pd )
        {
           pd = "BOOK\nPENCIL CASE\nPEN SET\nSTAPLER";
           pDisc = pd;
           return pd;
        }
        
        int setQuant ( int qu )
        {
           qu = 2, 3, 1, 1;
           quant = qu;
           return qu;
        }
        
        int setPpi ( int pi )
        {
           pi = 499, 250, 899, 250;
           ppi = pi;
           return pi;
        }
        
    private:
        string pNumber;	// part number
        string pDisc;        // part discription
        int quant;          // quanity
        int ppi;	            // price per item
        
    };
    
    // main function - driver //////////////////////////////////////////////////////
    //
    int main ( void )
    {
        Invoice in ( "", "", 0, 0 );
     	 
         cout << "INVOICE CLASS RESULTS:\n\n";
         in.setPrtNum("");
         in.getPrtNum(); 	 
    	 
        cin.get();  // freeze console window
        
        return 0;   // indicate program ended sucsessfully
    }

  2. #2
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    EDIT: Sorry, ive figured it out. I really should wake up and look at my code again before I panic! I forgot to send the getFunc() to cout to read the output. Sorry to waste a thread on my utter stupidiy! There, I saved you all the effort of pointing out a silly mistake. Thanks anyways

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM