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.

13 Years
Discussion Span
Last Post by alc6379

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;

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

Edited by pyTony: fixed formating


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.

This topic 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.