LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2015, 01:14 AM   #1
chilla101
LQ Newbie
 
Registered: Oct 2015
Posts: 7

Rep: Reputation: Disabled
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];

        }
    }
 
Old 11-11-2015, 01:31 AM   #2
psionl0
Member
 
Registered: Jan 2011
Distribution: slackware_64 14.1
Posts: 722
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
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.
 
Old 11-11-2015, 02:45 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,692

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
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....
 
Old 11-11-2015, 09:10 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,876
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by psionl0 View Post
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];
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: BASIC programming with Gambas for the beginner programmer LXer Syndicated Linux News 0 04-24-2014 12:22 PM
beginner programmer, database and network questions pjdell Programming 2 05-29-2011 09:34 AM
Using Puplet PupFlux412 on Toshiba 7000CT-Good choice for beginner Python programmer? linus72 Puppy 1 03-15-2009 01:04 AM
DSL for Newbie-Wanna-Be Python-beginner-programmer? linus72 DamnSmallLinux 1 02-27-2009 10:33 AM
Python - Beginner to Solid Programmer SirLancelotX Programming 3 07-08-2003 02:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration