LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Stuck at a ERROR pls help beginner programmer (https://www.linuxquestions.org/questions/programming-9/stuck-at-a-error-pls-help-beginner-programmer-4175558555/)

chilla101 11-11-2015 01:14 AM

Stuck at a ERROR pls help beginner programmer
 
my compiler is telling me it cant convert a std: string to char assignment. here is my code
Code:


#include <iostream>
#include <string>
using namespace std;

int main ()
{
    double rainFalls [12];
    string monthNames[] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    double avg = 0;
    double total = 0;
    double maxRain = 0;
    string highestMonth;
    double minRain = 0;
    string lowestMonth;

    //start entering inputs

    cout << "Please enter the amount of rainfall for each month in inches: " << endl;
    // test for positive integers
    for (int i = 0; i < 12; i++)
    {
        cout << monthNames [i] << ":";
        cin>> rainFalls[i];
// total= total + rainFalls[i];
            while (rainFalls[i] < 0)
            {
                cout << "ERROR. Please enter positive numbers" << endl;
                cout << monthNames[i] <<":";
                cin>> rainFalls[i];
            }
    }

    //CALCULATIONS AND MATH
    for (int i =0; i < 12; i++)
    {
      total= total + rainFalls[i];
    }
        avg= total/12;
        maxRain= rainFalls[0];//set to first number entered to array
        minRain= rainFalls[0];
    for (int i =0; i < 12; i++)
    {
        if (rainFalls[i] > maxRain)
        {
            highestMonth[i]= monthNames[i];
            maxRain= rainFalls[i];

        }
        if (rainFalls[i] < minRain)
        {
            lowestMonth[i]= monthNames[i];
            minRain= rainFalls[i];

        }
    }


psionl0 11-11-2015 01:31 AM

highestMonth and lowestMonth are single strings not arrays. That is the way you declared them (and I think you intended that).

However, in the body of the code you put
Code:

highestMonth[i]= monthNames[i];
...
lowestMonth[i]= monthNames[i];

which is an error.

pan64 11-11-2015 02:45 AM

your compiler also should tell you the line number and source file, not only the error message. Please post full error messages, not only parts....

rtmistler 11-11-2015 09:10 AM

Quote:

Originally Posted by psionl0 (Post 5447931)
highestMonth and lowestMonth are single strings not arrays. That is the way you declared them (and I think you intended that).

However, in the body of the code you put
Code:

highestMonth[i]= monthNames[i];
...
lowestMonth[i]= monthNames[i];

which is an error.

psion is correct and the actual change is that you just need to get rid of the [i] on the left hand side of those:
Code:

highestMonth = monthNames[i];
...
lowestMonth = monthNames[i];



All times are GMT -5. The time now is 04:54 AM.