Errors converting int to double

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cabenuts
    New Member
    • Jul 2007
    • 3

    Errors converting int to double

    Ok I have done this and it all works great. But now Im trying to take it a step further start small and add a little at a time yeah sounds good to me lol. Well anyway I need to take the numbers I get from this array and get the mean from them. I have tried numerous possibilites and cant get it to compile. Any suggestions I keep getting warnings converting int to double and things like this. Thanks in advance....
    [code=cpp]
    #include <iostream>
    #include <cstdlib>
    #include <iomanip>
    #include <fstream>

    using namespace std;

    double the_mean ( int a [ ], int size );

    int main ()
    {

    const int SIZE = 150;
    double a [ SIZE ];
    double data [SIZE];
    double input;
    int index = 0;

    ifstream fin;
    fin.open ("data07.fp100" );
    while ( fin >> input )
    {
    data [ index++ ] = input;
    if ( index >= SIZE ) break;
    }
    fin.close( );
    cout << "\n" << index << " fp numbers were read from disk file.";

    for ( int i = 0; i < index; ++i )
    {
    if ( i % 5 == 0 ) cout << "\n";
    cout << setw (14) << data [ i ];

    }
    cout << "\n";
    return EXIT_SUCCESS;
    }[/code]
    Last edited by sicarie; Jul 12 '07, 02:40 PM. Reason: Please use [code=cpp] and [/code] tags around your code.
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    That code should compile without error.
    You didn't post the code for the_mean() and the code you did post doesn't invoke that function.
    But notice that the_mean() takes an array of ints as a parameter, while the only arrays you've declared in main are type double.
    It sounds like you tried to pass one of those double arrays to your function, which would explain your error. The compiler won't convert a double to an int.

    Comment

    Working...