Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,562 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,888 people online right now. Registration is fast and FREE... Join Now!




index Error

 
Reply to this topicStart new topic

index Error

KMH
10 Apr, 2008 - 06:03 PM
Post #1

D.I.C Head
**

Joined: 23 Mar, 2008
Posts: 80

Hello,

I got the code working OK, then when I monved all my FunctionCall to main I got error, I don't know why it didn't work, but it work fine when I put it in the FunctionCall file. Can someone help me see what I did wrong???

CODE

#include <iostream>
#include <string>
#include "GreenFunction.h"

using namespace std;
char* get_num_month(int month);

int main()

{
    int mm = 0;
    char *month;
    char ch = 'y';
    static char arr[][10] = {"January","February","March","April","May","June","July","August","September","October","November","December"};
    while(ch == 'y' || ch == 'Y')
    {
        cout << "Enter month number I will display it in string: ";
        cin >> mm;
       if( mm < 1 || mm > 12 )// Validate to see if input for month is valid
            {
             cout << "INVALID month: Please try again." << endl;
             cin.get();
             system("pause");
             return 0;
            }
        else

        month = get_num_month(mm);
        //month++
        cout << "The month you entered: " << mm << " is :" << month << endl;
        cout << "Do you wish to enter another month number? <y/n> ";
        cin >> ch;
        cin.get();
    }
        cout << "Good bye and have a wonderfull day!" << endl;
cin.get();
return arr[month-1]; <<<<<< this were the error complained
//return 0;    
}


This is the error:error C2107: illegal index, indirection not allowed

This post has been edited by KMH: 10 Apr, 2008 - 06:09 PM
User is offlineProfile CardPM
+Quote Post

KYA
RE: Index Error
10 Apr, 2008 - 11:49 PM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,924



Thanked: 105 times
Dream Kudos: 1200
My Contributions
look at my last response in your other thread smile.gif

You can't have two return statements inside main()
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 11:44PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month