Thread: Issue with vector of vectors

  1. #1
    Registered User
    Join Date
    Nov 2017
    Posts
    2

    Issue with vector of vectors

    Hey all. I just joined this community and would really appreciate some help. In class right now we are dealing with a vector of vectors, that holds a bunch of different precipitation vlaues in it for many different months. It runs parallel to a vector that holds the index for the year/month. My issue is with one part we are looking for the month with the least rainfall and a different function looking for the month with the most rainfall. I tried both of them two different ways and neither are returning properly with the test values we were given.
    insert
    Code:
    ***********{LEAST GIVEN BELOW}*************************
    int least (vector<vector<double>>& precipitation, vector<int>& dates){
        double small, min;
        int date = 0, permDate = 0;
        small = accumulate(precipitation[0].begin(), precipitation[0].end(), 0.0);
        cout << small;
        min = small;
        for(vector<int>::size_type i = 1; i < dates.size(); ++i){
            date++;
            small = accumulate(precipitation[i].begin(), precipitation[i].end(), 0.0);
            if(small < min){
                min = small;
                permDate = date;
            }
        }
        permDate = permDate - 1;                                               
        return dates[permDate];                                                
    }
    *************{MOST GIVEN BELOW}*******************
    int most (vector<vector<double>>& precipitation, vector<int>& dates){
        int date = 0;
        int permDate = 0;
        double number;
        double greatest = 0;
        for(auto n : precipitation){
            number = 0;
            date++;
            number = total(precipitation, (date-1));
            if(number > greatest){
                greatest = number;
                cout << greatest << endl;
                permDate = date;
            }                                        
        }
        permDate = permDate - 1;                                              
        return dates[permDate];                                               
    }
    
    *****{MOST USES FUNCTION TOTAL, GIVEN BELOW}***********
    double total(vector<vector<double>>& precipitation, int n){
        double all = 0;
        for(auto a : precipitation[n]){
            all = all + a;
        }
        return all;
    }
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Nov 2017
    Posts
    2
    The issue is that neither of these methods set number back to 0, and it just keeps adding on top of the values from the previous months. Any help would be amazing, thank you guys.

  3. #3
    Banned
    Join Date
    Aug 2017
    Posts
    861
    spDataProcHWprecip.cpp:40:55: error: '>>' should be '> >' within a nested template argument list

  4. #4
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    779
    Quote Originally Posted by userxbw View Post
    spDataProcHWprecip.cpp:40:55: error: '>>' should be '> >' within a nested template argument list
    That isn't an issue anymore, not since C++11 at least.

    @xtyler: Give an example of the input, and the output you expect. Chances are, you'll find the error yourself while preparing the demonstration. Without that it's fairly challenging to help.

  5. #5
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by -Adrian View Post
    That isn't an issue anymore, not since C++11 at least.

    @xtyler: Give an example of the input, and the output you expect. Chances are, you'll find the error yourself while preparing the demonstration. Without that it's fairly challenging to help.
    Code:
    std=c++11 `
    well I fixed it anyways, out
    Last edited by userxbw; 11-09-2017 at 05:30 PM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,323
    An example rainfall.txt would make it so much easier for us to get up and running and testing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 09-22-2013, 07:00 AM
  2. Vector Of Vectors
    By Khadafi in forum C++ Programming
    Replies: 11
    Last Post: 12-30-2011, 12:04 PM
  3. Vector of Vectors
    By Zosden in forum C++ Programming
    Replies: 6
    Last Post: 10-05-2008, 01:30 AM
  4. vector of vectors
    By xddxogm3 in forum C++ Programming
    Replies: 11
    Last Post: 05-04-2007, 10:25 AM
  5. vector of vectors
    By Magos in forum C++ Programming
    Replies: 2
    Last Post: 03-26-2004, 03:46 AM

Tags for this Thread