Hi
I'm writing a program for a school project for generating Pay Slips. Here's the code
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
char name[30];
char surname[30];
char id[30];
double hourrate;
char hourratechar[30];
int numhour;
char numhourchar[10];
char taxcredit[10];
float taxoutput;
float basicpay;
float overtime;
float grosspay;
float natins;
cout <<"Please enter your name"<<endl;
do
{
cin.getline(name,40);
if(strlen(name) > 30)
{
cout<<"Error please enter sufficient characters"<<endl;
}
}while(strlen(name) > 30);
cout <<"Please enter your surname"<<endl;
do
{
cin.getline(surname,40);
if(strlen(surname) > 30)
{
cout<<"Error please enter sufficient characters"<<endl;
}
}while(strlen(surname) > 30);
cout <<"Please enter your ID"<<endl;
do
{
cin.getline(id,15);
if(strlen(id) > 5)
{
cout<<"Error please enter 5 numbers or less"<<endl;
}
}while(strlen(id) > 5);
cout <<"Please enter your hourly rate"<<endl;
cin.getline(hourratechar,30);
hourrate= atof(hourratechar);
do
{
cout <<"Please enter the number of hours you work"<<endl;
cin.getline(numhourchar,30);
numhour= atoi(numhourchar);
if(numhour > 60)
{
cout<<"Error please enter 60 hours or less"<<endl;
}
}while(numhour > 60);
if (numhour<=39)
{
basicpay=numhour*hourrate;
}
else
{
basicpay=39*hourrate;
}
if (overtime <= 39){
overtime = 0;
}
else
if (overtime > 39) {
overtime=numhour*hourrate*1.5;
}
grosspay=basicpay+overtime;
cout <<"Please enter whether you get tax credits or not"<<endl;
cin.getline(taxcredit,10);
if (taxcredit[0]== 'y')
{
taxoutput=grosspay*0.22;
}
else
{
taxoutput=grosspay*0.20;
}
natins=grosspay*0.11;
cout <<""<<endl;
cout <<"The employee entered the following information:"<<endl;
cout <<"Their name" <<endl<<name;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their surname" <<endl<<surname;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their ID" <<endl<<id;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Hour Rate" <<endl<<hourrate;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Working Hours" <<endl<<numhour;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Basic Pay" <<endl<<basicpay;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Overtime Pay" <<endl<<overtime;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Gross Pay" <<endl<<grosspay;
cout <<""<<endl;
cout <<""<<endl;
cout <<"Their Tax Credits" <<endl<<taxoutput;
cout <<""<<endl;
cout <<""<<endl;
cout <<"National Insurance" <<endl<<natins;
cout <<""<<endl;
cout <<""<<endl;
system("pause");
}
I was just wondering on all the cin.getline inputs how would you go about writing it to a basic text file. I've found the basic info but I can't seem to put it to good use.
Cheers
Tom Evans