
June 20th, 2002, 10:43 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
Here is a simple version of how to do this, but this sounds generally like a homework assignment. If this is so, then you really need to complete these on your own. The code I listed is actually a mix between C++ and C and was written in Linux, but it should work correctly on a win compiler also.
Code:
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <iostream.h>
using namespace std;
#define TAX_RATE .30
int main(void) {
char *first,
*last,
*ssn,
*test,
*final_output;
float hours=0,
pay_rate=0,
gross=0,
taxes=0,
net=0;
/*-- lets create the variables --*/
final_output = new char[1024];
first = new char[50];
last = new char[50];
ssn = new char[12];
test = new char[1024];
/*-- start the loop --*/
do {
/*-- get first & last name --*/
cout << "First Name: ";
cin >> first;
cout << "Last Name: ";
cin >> last;
/*-- get ssn with error checking on length only --*/
do {
cout << "SSN: ";
cin >> ssn;
if (strlen(ssn) == 11)
break;
else
cout << "Invalid ssn. Must be in format 999-99-9999";
} while (1);
/*--
get pay rate with error checking on
null and 0 values
--*/
do {
cout << "Pay Rate: ";
cin >> test;
if (test == NULL)
cout << "Invalid pay rate.";
else if(atof(test) != 0)
break;
else
cout << "Invalid pay rate.";
} while (1);
pay_rate=atof(test);
/*--
get hours worked with error checking on
null and 0 values
--*/
do {
cout << "Hours Worked: ";
cin >> test;
if (test == NULL)
cout << "Invalid amount of hours.";
else if(atof(test) != 0)
break;
else
cout << "Invalid amount of hours.";
} while (1);
hours=atof(test);
/*-- calculate values --*/
gross=hours*pay_rate;
taxes=gross*TAX_RATE;
net=gross-taxes;
/*-- set out precision --*/
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
/*-- create output --*/
sprintf(final_output,"\n\n%s %s ssn(%s)\n------------------------------\n",
first,last,ssn);
cout << final_output;
cout << "Gross: " << gross << endl;
cout << "Taxes: " << taxes << endl;
cout << "Net: " << net << endl << endl;
/*-- do another? --*/
cout << "Calculate Another? (y/n)?";
cin >> test;
/*-- check first value of string for y/Y --*/
} while (!strncasecmp(test,"y",1));
/*-- return memory to the heap --*/
delete [] first;
delete [] last;
delete [] ssn;
delete [] test;
return 1;
}
|