Laugh if you must, but i still need help

This is a discussion on Laugh if you must, but i still need help within the C++ Programming forums, part of the General Programming Boards category; Well...i'm supposed to write a program that uses a datafile as the input. We're supposed to create a table of ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    19

    Laugh if you must, but i still need help

    Well...i'm supposed to write a program that uses a datafile as the input. We're supposed to create a table of salaries based on the amount of sales and commission.

    The input I've created as a datafile is:
    250
    561
    736
    832
    841
    934
    975
    1069
    1100
    1399
    1500
    1739
    2222
    4428
    5233
    6175
    7419
    8850
    -1
    The output is supposed to look like this somewhat:

    Ranges: Number of People:
    $200-299 9
    $300-399 3
    $400-499 0
    $500-599 1
    $600-699 1
    $700-799 1
    $800-899 1
    $900-999 1
    $1,000 and over 3

    I'm a newbie and have no clue on how to do arrays...initialize and use....and I still have problems with my coding...can u take a look and help with what i need to fix to straighten things out?

    // Program 6 - No Extra Credit
    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    void salary[data410.dat];

    #include <iomainp>

    using std::setw;

    int main ()
    {
    float s[ 9 ] = { $200-299, $300-399, $400-499, $500-599, $600-699,
    $700-799, $800-899, $900-999, $1,000 and over };

    cout<<"Range"<<setw(14)<<"Number of People"<<endl;

    for (s = 0; s < 20; s++)
    cout<<setw(15)<<s[s]<<setw(15)<<s<<endl;

    salary(int sales);

    return 0;
    }

    void salary(int sales)
    {
    float salary;

    cin>>sales;
    while (salary != -1);
    salary = 200 + (sales * 0.09);
    }

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    you'll have to use file handling in your code.

    read from the data from the file
    if it lies between some level increase that levels number by 1

    like if you read 250 then value of level $200-299 should be increased by 1 and so on

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    19
    HUH?

  4. #4
    Unregistered
    Guest
    declare an array of 9 ints called s. declare an ifstream, open it and associate it with your file. while not end of file read file data into a variable of type int called sales one at a time. As each sales figure is read in send value to function to convert sales to salary. Evaluate salary using a series of if statements incrementing appropriate counter in the array using the following as an example:

    if(salary > 200 && < 300)
    s[0]++;
    else if(salary > 300 && < 400)
    s[1]++;
    etc.

    prepare summary statement to print out for user.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laugh at my work day
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 06-14-2006, 12:13 PM
  2. Please don't laugh...SIMPLE loop question!
    By the_lumin8or in forum C++ Programming
    Replies: 5
    Last Post: 03-31-2006, 12:08 PM
  3. feel free to laugh at my code!
    By JimJamJovi in forum C Programming
    Replies: 4
    Last Post: 01-11-2002, 03:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21