473,387 Members | 1,542 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

C++ Program help

32
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?


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std; 
  4.  
  5.     float grosspay();
  6.     float netpay(float);
  7.  
  8.  
  9.     int main()// Starts the program
  10.     {
  11.  
  12.  
  13.  
  14.     float gross=0;// Declares gross as a float
  15.     int num = 1; // Declares num as a int
  16.     float hours=0;// Declares hours as a float
  17.  
  18.  
  19.  
  20.     while(num<=4)// beginning of a while loop counts up to 4
  21.         {
  22.  
  23.  
  24.             gross=grosspay();// Calls the function
  25.             netpay(gross);// Calls the function
  26.  
  27.         }
  28.  
  29.     return 0;
  30.     }
  31.  
  32.     float grosspay()// Begins the funtion outside of main
  33.     {
  34.         ifstream infile;
  35.         infile.open("C:\Documents and Settings\dckorneg\Desktop");
  36.         float payrate;// Declares
  37.         float hours;// Declares
  38.         float gross;// Declares
  39.         cout<< " Hello please Enter the employees payrate "<<endl;// Displays
  40.         infile>>payrate;// Reads in
  41.  
  42.         cout<<" Hello please enter the amount of hoursworked"<<endl;//Displays
  43.         infile>>hours;// Reads in
  44.  
  45.  
  46.         gross =  hours * payrate;// Formula
  47.  
  48.         cout<<" The grosspay for this employees is "<<gross<<endl;//Displays 
  49.  
  50.         return gross; // Returns the value of gross
  51.     }
  52.  
  53.     float netpay(float gross)// The function outside of main
  54.     {
  55.  
  56.         float fedtaxes;// Declares as float
  57.         float statetaxes;// Declares as float
  58.         float netpay;//Declares as float
  59.         float state = .06;// Declares as float
  60.         float fed = .15;// Declares as float
  61.         statetaxes = gross * state;// Formula
  62.         fedtaxes = gross * fed;// Formula 
  63.         netpay = gross-statetaxes-fedtaxes;//Formula
  64.  
  65.         cout<<" This is your state taxes: "<<statetaxes<<endl;// Displays
  66.         cout<<" This is your federal taxes: "<<fedtaxes<<endl;// Displays
  67.         cout<<" This is your netpay: "<<netpay<<endl;// Displays
  68.  
  69.         return netpay;
  70.  
  71.     }
Sep 20 '07 #1
4 1307
Ganon11
3,652 Expert 2GB
Sure, what seems to be the trouble?
Sep 20 '07 #2
compsci
32
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
Sep 21 '07 #3
Ganon11
3,652 Expert 2GB
The character '\' is used for escape sequences, so you need to use the character '\\' to have a single '\' printed.
Sep 21 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
In addtion, you need to chekc that your file opened.
infile.open("C:\Documents and Settings\dckorneg\Desktop");
//Did the file open??
//For reading??
//For writing??
Sep 21 '07 #5

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

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
2
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
12
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .......
9
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.