Thread: Array Problem
View Single Post
Old 07-14-2005, 05:46 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,720
redhead is on a distinguished road
Here is my example.. It is nothing like the one you're working on..
Code:
/* This program computes the amount of employees 
 * who receive a salary in a set number of ranges.
 * 
 * Assignment 4.10
 */

#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;


double calculateSalary (double totalEarned){ 
  return ((totalEarned*0.09) + 200.0);
}

int main() //begins program execution
{
  double earnings = 0.0; 

  /* allways make room for one more than your index count */
  int pay[]= {0,0,0,0,0,0,0,0}; /* for ease we initialize it as 0 */

  while (true) 
    {
      cout << "Enter total sales for employee";
      cout << " (Enter -1 to stop and tabulate) : ";
      cout.flush();
      cin >> earnings;
      if(earnings == -1.0)
	break;
      for(int i = 0, amount=300; i < 8; ++i, amount+=100)
	if(earnings < amount)
	  {
	    pay[i] = pay[i] + 1;
	    break;
	  }
      cout << "Here is the total salary of employee: $" 
	   << calculateSalary(earnings) << endl;
    }
  cout << "The earnings are as follows:" << endl;
  for(int i=0, amount=300; i < 8; ++i, amount+=100)
    cout << "(" << amount-100 << " <= Amount < " << amount 
	 << ") Count: " << pay[i] << endl;
  return 0;
}
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote