-
Loops
I am stuck trying to write a loop that will conitunually ask for an employee number, gross pay, tax, and fed tax. the loop terminates when the user types in 0 as employee number, then program displays results for each employee:
I go this so far:
cout <<"Enter employee number: ";
cin >> number;
while (number > 0)
{
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
cout <<"Enter gross pay: $";
cin>> grosspay;
cout <<"Enter State tax: $";
cin >> statetax;
cout <<"Enter fica: $"<<"\t";
cin >>fica;
cout <<endl;
I can't figure out how to loop it but keep the original employee number, meaning if someones number is 100 and the next number is 235, it won't switch the emplloyee numbers with the loop count
Any help would be appreciated
-
well for number use an array;
http://www.cprogramming.com/tutorial/lesson8.html
As for the loop:
do
{
cout <<"Enter employee number: ";
cin >> number;
while (number > 0)
{
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);
cout <<"Enter gross pay: $";
cin>> grosspay;
cout <<"Enter State tax: $";
cin >> statetax;
cout <<"Enter fica: $"<<"\t";
cin >>fica;
cout <<endl;
}
while (number != 0);
-
Loops
I can't use an array, we aren't allowed. Plus i dont' know the set number of employees. How do I get each employee number and info to appear, but on seperate lines once the lopp is terminated?
-
you would, if useing, output each part of the array with the "\n" or endl; function....
Are you allowed to use vectors?
-
Loop
No, I can't use vectors
I thought this would be fairly simple but I am stuck on showing the data after the termination of the loop
-
Given the constraints of your assignment, the only thing to do that I can see is to store the data into one long string. That is, concatenate each new employee number plus financial data to a single string.
This will require some type of delimiting in order to produce a "line feed" between employees in the display code not to mention the separation of data elements for each.
This will make your loop rather bulky, but, off the top of my head, seems workable. (Just running an idea up the flagpole here...)
P.S. On a 32-bit Windows system, a string may occupy well over four billion bytes, so the number of employees shouldn't pose a real problem.
P.P.S. You needn't include setprecision() and 'fixed' within the loop. Once set, you must unset them to implement a change. 'setwidth()' is the rascal that holds for only one element. :)
-Skipper
-
Are you supposed to use a FILE???
-
Thought about that one, too.
(Actually, my first thought. Unfortunately, all we've got to work with is what we don't have to work with. We need more input! :))
-Skipper