Thread: c++ help

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    16

    c++ help

    I'm having trouble with a part of my homework assignment...
    I'm not asking for the answer, i just need some pointers! I'm not even sure where to start! (is the answer in the form of a pointer, array, structure, ???) Ive been trying for the past 10hrs straight with hardly anyluck and would love a sample or two, before i start crying

    Question:
    As facility engineer at a construction site for a new theater, you have been asked by the project architect to determine how many seats need to be ordered in order to fill the theater. The architect wants the seating arrangement to fanout from the stage such that the row of seats nearest the stage has 14 seats with each succeeding row towards the back of the theater has 2 more seats per row than the previous row. When completed, the theater will have a total number of (36) rows.
    1-Devise a algorithm which expresses the solution to this problem.
    2-Write and run a short C++ program which uses the algorithm to display a tabular listing of the row and the number of seats in that row. Finally, output the total number of seats needed.

    Thanks for your time,
    Steve

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> is the answer in the form of a pointer, array, structure, ???)

    Read the question...

    >>> how many seats need to be ordered

    ... this can only be a single integer value can't it. You can't order a pointer to an array can you?

    You need a counter variable, and then loop through the number of seat rows adding 2 to the counter for each iteration, write out the row number and the variable as you go to produce your table.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    16
    (((Hmm could this work? This displays the row # & amount of seats in reach row)))

    #include <iostream.h>
    int main()
    {
    int row=0;
    int seats=12;
    do
    {
    row = row++;
    seats = seats + 2;
    cout << "row " << row << " has "<< seats <<
    " seats" << endl;
    }
    while (row<36);
    -----------------------------------------------------------------
    OUTPUT:
    row 1 has 14 seats
    row 2 has 16 seats
    all the way to
    row 36 has 84 seats

    But now im having a hard time finding the total amount of seats!!
    i've tried several things to no avail,
    could something like this work?
    int sumSoFar = 0;
    for (int i = 1; i <= 36; i = i + 1)
    sumSoFar = sumSoFar + i;
    cout << "The sum is: " << sumSoFar << endl;

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    16
    Here's a prettier version, but i still cant find a way to tally the sum of seats...

    #include <iostream.h>
    #include <iomanip.h>
    int main()
    {
    const float STARTROW = 14;
    const float INCREMENT = 2;
    long rowtotal = STARTROW;
    int row;

    cout << "Row Seats\n";
    cout << "---- -----\n";
    for (row = 1; row <= 36; row++)
    {
    cout << setw(3) << row << setw(12) << rowtotal << endl;
    rowtotal += INCREMENT;
    }

    return 0;
    }

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    in your first version declare an int called totalSeats and intialize to zero outside the loop. Inside the loop increment totalSeats by seats each time through the loop. Output totalSeats only after the loop has been completed.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    16
    thanks!!!, i love you finally works...
    i spent 10+hrs on this question, and your reply made it look real easy!!

    ------------

    i spent a couple more hours on this, worked on an algorithim that implemented into the code, and i must say its a lovely program now... thanks for all the help..
    Last edited by zipfur; 12-10-2001 at 07:04 PM.

Popular pages Recent additions subscribe to a feed