0

I haven't coded in c++ for over a year, I can't see the error in this code.

It says the cin function is having an error, no such operator >>

int main()
{
    double * array[25];
    bool exitCode = false;
    cout <<"Enter in your Array"<<endl;
    do{
        for(int i = 0; i < 24; i++)
        {
            cout<< "Enter your float number";
            cin >> array[i];

            cout << "Are there any more inputs?: ( Y or N )";
            cin >> exitCode; // error is here
        }
    }while(exitCode == false);

    return array;
}

4 Answers 4

2

Make sure you're including the following :

<fstream>
<istream>
<iostream>
<string>
Sign up to request clarification or add additional context in comments.

2 Comments

don't forget using namespace std; :p
Agreed! hehe I assume he was since he wasn't getting any error on the cout ! Thanks for pointing it out though!
1

try this:

#include<iostream>

using namespace std;

int main()
{
    double array1[25];
    char exitCode;
    cout <<"Enter in your Array"<<endl;
    do{
        for(int i = 0; i < 24; i++)
        {
            cout<< "Enter your float number";
            cin >> array1[i];

            cout << "Are there any more inputs?: ( Y or N )";
            cin >> exitCode; // error is here
        }
    }while(exitCode == 'y');

    return 0;
}

i wonder why you're using a pointer and an array when you only store it on the array(and not using the pointer) >.>

and thus, exitCode is boolean(which i think is the reason why it's got an error)

Comments

1

Lets take this line by line:

Change

double * array[25];

to

double array[25];

Reason: double * is a pointer to a double, so in the original you declared an array of 25 pointers, but there is no reason why you should use pointers here. You want an array of 25 doubles.

do{
    for(int i = 0; i < 24; i++)

You declared a for loop inside the while loop. You only need one loop in your example.

cout << "Are there any more inputs?: ( Y or N )";

You are asking for character input from the user. However cin >> exitCode; is reading a bool, you probably wanted to read a char.

return array;

Your returning an array, main returns an int.

Here is the code with the above fixes and proper includes:

#include <iostream>
using namespace std;
int main()
{
double array[25];
cout <<"Enter in your Array"<<endl;

for(int i = 0; i < 24; i++)
{
    cout<< "Enter your float number";
    cin >> array[i];

    cout << "Are there any more inputs?: ( Y or N )";
    char c;
    cin >> c;
    if (c == 'N')
    {
        break;
    }
}

return 0;
}

Comments

0

You declared 'array' to be be an array of pointers to doubles. I doubt that is what you actually want, but, anyway, the '<<' operator on 'cin' doesn't support that, so this is invalid:

cin >> array[i];

You would have to change it to

cin >> *array[i];

to make it compile. (It won't run due to the pointers not being initialized.)

I think what you probably want is for 'array' just to be an array of doubles.

2 Comments

I know. That's why I said that's probably not what he wants.
Well, it will compile, but the program will crash when it dereferences an uninitialized pointer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.