none
Question flagged and requires additional verification

    Question

  • When I try to post the following under Visual Studio Languages C++ Standards, Extensions and interop I a message saying my post has been flagged and requires additional verification. Why am I getting this message and why are my questions being deleted upon this action. I not trying to do anything unusual just post something similiar to the following as always:

    I have to write a program that does the following:

    Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program  that stores  this information in a two-dimensional 3 × 7 array , where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers  1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday". The program  should first prompt the user to input the data for each monkey, starting with "Sunday" for monkey #1, then monkeys #2 and #3, followed by "Monday" for monkey #1, then monkeys #2 and #3 and so on, through "Saturday". The program  then creates a report that includes the following information, each properly labeled (see below): 

    • Average amount of food eaten per day by the whole family of monkeys.
    • The least amount of food eaten during the week by any one monkey.
    • The greatest amount of food eaten during the week by any one monkey.

    Input Validation: Do not accept negative numbers for pounds of food eaten. When a negative value  is entered, the program outputs  "invalid (negative) food quantity -- re-enter" and attempts to reread the value . Prompts And Output  Labels: Decimal values  should be displayed using default  precision, i.e. do not specify precision. Each item read should be prompted for by a string  of the form "Enter the food eaten by monkey #N on DAY:" when N is 1 or 2 or 3 and DAY is "Sunday" or "Monday" or ... or "Saturday". The output  should be of the form:         Average food consumed daily: 6.23         The least daily food consumed was by Monkey #0 on Friday         The most daily food consumed was by Monkey #2 on Sunday where the specific amount of food or specific monkeys or specific days identified depend on the actual input. 

    However, I keep getting the following errors for the following lines of code:

             4        IntelliSense: no suitable constructor exists to convert from "std::string [7]" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>"                38       15         Fall2014monkeyBusiness

             5        IntelliSense: no suitable constructor exists to convert from "std::string [7]" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>"                41       22         Fall2014monkeyBusiness

             6        IntelliSense: no suitable constructor exists to convert from "std::string [7]" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>"                48       19         Fall2014monkeyBusiness

    Error    1        error C2664: 'void getFoodEaten(std::string,double [][7])' : cannot convert argument 1 from 'std::string [7]' to 'std::string'             32       1        Fall2014monkeyBusiness

    Error    3        error C2664: 'void displayMostEaten(std::string,double [][7])' : cannot convert argument 1 from 'std::string [7]' to 'std::string'           42       1        Fall2014monkeyBusiness

    Error    2        error C2664: 'void displayAverageDaily(std::string,double [][7])' : cannot convert argument 1 from 'std::string [7]' to 'std::string'           35       1        Fall2014monkeyBusiness

    // Get the amount eaten
             getFoodEaten(DAYNAME, food);
     
             // Display the average amount of food eaten daily by each monkey
             displayAverageDaily(DAYNAME, food);
             //displayAverageDaily(average);

    and this line of code:

    // Display the most eaten in a day by any one monkey

             displayMostEaten(DAYNAME, food);

    , but I have no idea why or how to resolve it.

    I tried the following:

    //std::string DAYNAME = "";

    //std::string::c_str(DAYNAME);

    //string FinalDAYNAME = static_cast<string>(day) + DAYNAME(day)

    //const string FinalDAYNAME = static_cast<string>(day)+DAYNAME(day)

    , but they don't seem to help and create new problems. Could someone explain what I'm doing wrong and show proper examples of how to convert DAYNAME where ever its supposed to be converted?

    My code is as follows:

    #include <iostream>

    #include <iomanip>

    #include <string>

    using namespace std;

     

    // constants

    const int MONKEYS = 3;

    const int DAYS = 7;

    //std::string DAYNAME = "";

    //std::string::c_str(DAYNAME);

    //string FinalDAYNAME = static_cast<string>(day) + DAYNAME(day)

    //const string FinalDAYNAME = static_cast<string>(day)+DAYNAME(day)

     

    // Function Prototypes

    //void getFoodEaten(double[][DAYS]);

    void getFoodEaten(string, double[MONKEYS][DAYS]);

    //void displayAverageDaily(double[][DAYS]);

    void displayAverageDaily(string, double[MONKEYS][DAYS]);

    void displayLeastEaten(double[MONKEYS][DAYS]);

    //void displayMostEaten(double[][DAYS]);

    void displayMostEaten(string, double[MONKEYS][DAYS]);

     

    int main()

    {

             // Array to hold the monkey data

             string DAYNAME[DAYS] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };

             double food[MONKEYS][DAYS];

            

             // Variables

             //string FinalDAYNAME = static_cast<string>(day) + DAYNAME(day)

     

             // Get the amount eaten

             getFoodEaten(DAYNAME, food);

     

             // Display the average amount of food eaten daily by each monkey

             displayAverageDaily(DAYNAME, food);

             //displayAverageDaily(average);

     

             // Display the least amount eaten in a day by any one monkey

             displayLeastEaten(food);

     

             // Display the most eaten in a day by any one monkey

             displayMostEaten(DAYNAME, food);

     

             cin.ignore();

            

             cin.get();

     

             return 0;

             } //end main()

     

             // getFoodEaten() function

     

    //void getFoodEaten(double food[][DAYS])

    void getFoodEaten(string DAYNAME, double food[MONKEYS][DAYS])

             {

                     int monkey = 0;

     

                     for (int day = 0; monkey < MONKEYS; monkey++)

                     {

                              for (int day = 0; day < DAYS; day++)

                              {

                                       // get the amount eaten by this monkey on this day

                                       //cout << "Enter the pounds eaten by monkey number "

                                                //<< (monkey + 1) << "\non day " << (day +1)

                                                //''<< ": ";

                                       cout << "Enter the pounds eaten by monkey number "

                                                << (monkey + 1) << "\non day " << static_cast<int>(DAYNAME[day])

                                                << ": ";

                                       cin >> food [monkey][day];

     

                                       // Validate the input

                                       while (food[monkey][day] < 0)

                                       {

                                                cout << " Enter a non-negative number: ";

                                                cin >> food[monkey][day];

                                       } // end while

                              } // end inner for

                     } // end outer for

             } // end getFoodEaten()

     

     

    // void displayAverage Daily() function

     

    //void displayAverageDaily(double food[][Days])

    void displayAverageDaily(string DAYNAME, double food[MONKEYS][DAYS])

    {

             double total;    // Accumulator

             double average;  // average eaten

     

             for (int day = 0; day < DAYS; day++)

             {

                     // initialize the accumulator

                     total = 0.0;

                     // get the total eaten by the monkey on this day

                     for (int monkey = 0; monkey < MONKEYS; monkey++)

                              total += food[monkey][day];

                     // calculate the average eaten

                     average = total / MONKEYS;

                     // display the average

                     //cout << "The average amount eaten on day " << (day + 1)

                              //<< " is " << average << " pounds.\n";

                     //cout << "The average amount eaten on " << DAYNAME << " is "

                              //<< average << " pounds.\n";

                     cout << "The average amount eaten on " << static_cast<int>(DAYNAME[day]) << " is "

                              << average << " pounds.\n";

             } // end for

    } // end displayAverageDaily()

     

    // displayLeastEaten() function displas the least amount of food eaten

             // by a Monkey in a day.

     

             //void displayLeastEaten(double food[][DAYS])

    void displayLeastEaten(double food[MONKEYS][DAYS])

    {

             double leastFood; // holds the least amount

             int leastMonkey; // monkey eating the least

             int leastDay;    // Day with the least

     

     

     

             leastMonkey = 0;

             leastDay = 0;

             leastFood = food[leastMonkey][leastDay];

     

             // step through the array comparing the variables

             for (int monkey = 0; monkey < MONKEYS; monkey++)

             {

                     for (int day = 0; monkey < MONKEYS; monkey++)

                     {

                              if (food[monkey][day] < leastFood)

                              {

                                       leastFood = food[monkey][day];

                                       leastDay = day;

                                       leastMonkey = monkey;

                              } // end if

                     } // end inner for

             } // end outer for

    } // end displayLeastEaten Function

     

             // displayMostEaten() function displas the most amount of food eaten

             // by a Monkey in a day.

             //void displayMostEaten(double food[][DAYS])

    void displayMostEaten(string DAYNAME, double food[MONKEYS][DAYS])

    {

             double mostFood; // holds the least amount

             int mostMonkey; // monkey eating the least

             int mostDay;     // Day with the least

     

             // Assume the most amount was eaten on this day

             // by the fist monkey

     

             mostMonkey = 0;

             mostDay = 0;

             //mostFood = food[monkey][leastDay];

             mostFood = food[mostMonkey][mostDay];

     

             // step through the array comparing the variables

             for (int monkey = 0; monkey < MONKEYS; monkey++)

             {

                     for (int day = 0; monkey < MONKEYS; monkey++)

                     {

                              if(food[monkey][day] < mostFood)

                              {

                                       mostFood = food[monkey][day];

                                       mostDay = day;

                                       mostMonkey = monkey;

                              } // end if

                     } // end inner for

             } // end outer for

     

             // Display results

             //cout << "Monkey number " << (mostMonkey + 1)

                     //<< " ate the most amount of food,\n"

                     //<< mostFood << " pounds, on day " << (mostDay + 1)

                     //<< endl;

             cout << "Monkey number " << (mostMonkey + 1)

                     << " ate the most amount of food,\n"

                     << mostFood << " pounds, on day " << DAYNAME

                     << endl;

    } // end displayMostEaten()


    Friday, October 31, 2014 8:55 PM

Answers