C++ Program help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compsci
    New Member
    • Jan 2007
    • 32

    C++ Program help

    Im tryin to read the hours and payrate for 75 employees from a called file “employee.data” . This is what I have so far. Can anyone help me?


    Code:
    #include <iostream>
    #include <fstream>
    using namespace std; 
    
    	float grosspay();
    	float netpay(float);
    	
    
    	int main()// Starts the program
    	{
    
    
    
    	float gross=0;// Declares gross as a float
    	int num = 1; // Declares num as a int
    	float hours=0;// Declares hours as a float
    
    
    
    	while(num<=4)// beginning of a while loop counts up to 4
    		{
    
    			
    			gross=grosspay();// Calls the function
    			netpay(gross);// Calls the function
    			
    		}
    	
    	return 0;
    	}
    
    	float grosspay()// Begins the funtion outside of main
    	{
    		ifstream infile;
    		infile.open("C:\Documents and Settings\dckorneg\Desktop");
    		float payrate;// Declares
    		float hours;// Declares
    		float gross;// Declares
    		cout<< " Hello please Enter the employees payrate "<<endl;// Displays
    		infile>>payrate;// Reads in
    
    		cout<<" Hello please enter the amount of hoursworked"<<endl;//Displays
    		infile>>hours;// Reads in
    		
    
    		gross =  hours * payrate;// Formula
    
    		cout<<" The grosspay for this employees is "<<gross<<endl;//Displays 
    
    		return gross; // Returns the value of gross
    	}
    
    	float netpay(float gross)// The function outside of main
    	{
    
    		float fedtaxes;// Declares as float
    		float statetaxes;// Declares as float
    		float netpay;//Declares as float
    		float state = .06;// Declares as float
    		float fed = .15;// Declares as float
    		statetaxes = gross * state;// Formula
    		fedtaxes = gross * fed;// Formula 
    		netpay = gross-statetaxes-fedtaxes;//Formula
    
    		cout<<" This is your state taxes: "<<statetaxes<<endl;// Displays
    		cout<<" This is your federal taxes: "<<fedtaxes<<endl;// Displays
    		cout<<" This is your netpay: "<<netpay<<endl;// Displays
    
    		return netpay;
    
    	}
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    Sure, what seems to be the trouble?

    Comment

    • compsci
      New Member
      • Jan 2007
      • 32

      #3
      Originally posted by Ganon11
      Sure, what seems to be the trouble?
      In my function gross pay i have the hours and payrate reading from the file. But it is not working

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        The character '\' is used for escape sequences, so you need to use the character '\\' to have a single '\' printed.

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          In addtion, you need to chekc that your file opened.
          Originally posted by compsci
          infile.open("C: \Documents and Settings\dckorn eg\Desktop");
          //Did the file open??
          //For reading??
          //For writing??

          Comment

          Working...