0

This is my first post here and so far I have been doing fine in my last C++ class but right now I am stuck. I have to make a program using an array that is initialized dynamically. You have to make a program that will input the rooms of a house;n, and then ask for the user to input the size of each of the rooms until it is done. Then you have to scan the array for the largest room and output its dimensions. I know that you have to do it as a vector so that you can input the data. I just have no idea on how to start this. Please help.
Anthony

3
Contributors
4
Replies
5
Views
12 Years
Discussion Span
Last Post by alc6379
0

HERE ................

#include <iostream>
#include <vector>

int main()
{
    using namespace std;
    vector< pair<int,double> > Dim;
    vector< pair<int,double> >::iterator itr,largest;
    int Rooms(0), W, H;

    cout << "Rooms of a house :>";
    cin >> Rooms;

    cout << "Dimensions format : W * H" << endl;
    for (int i=1 ; i <= Rooms ; ++i) {
        cout << "Room "<< i << " Dimensions:> ";
        cin >> W >> H;
        Dim.push_back( make_pair(i,W*H) );
    };

    largest = Dim.begin();
    itr = Dim.begin()+1;
    while (itr != Dim.end()) {
        if ( (*itr).second > (*largest).second)
            largest = itr;
        ++itr;
    };

    cout << "Room " << (*largest).first << " With Dimensions Size " << (*largest).second
         << " Is The Largest Room" << endl;
    return 0;
}

Edited by pyTony: fixed formating

0

Thanks, INTEL
I didn't expect to get that much but now that I see it now I will be able to figure out everything and learn that way.
Anthony

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.