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

Recommended Answers

All 4 Replies

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;
}

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

No problem ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.