i need help

This is a discussion on i need help within the C++ Programming forums, part of the General Programming Boards category; I need help with my program. Everytime that I try to compile my program I keep getting the same error ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    Unhappy i need help

    I need help with my program. Everytime that I try to compile my program I keep getting the same error messages. I tried almost everything to get rid of the error messages, but I can't.
    Here's my program & error messages:

    // necessary library header files:

    #include<iostream.h>

    #include<fstream.h>

    #include<iomanip.h>

    #include<string.h>



    // global user-defined types:

    struct Storm {

    int beginDate;

    int duration;

    char name[15];

    int category;

    int wind;

    int pressure;

    };



    // function prototypes:

    int GetRecord( ifstream &input, int &y,int &m, int &d, int &h,

    int &s, char name[], int &wind, int &pres);

    Storm* GetStorm( ifstream& input );

    int SaffirSimpson( int w );

    void Sort( Storm* List[], int NStorms );

    void DisplayStorms( char* title, Storm* List[], int NStorms );

    void PrintStorm( Storm* StormPointer );



    // Constants

    const int MAX_STORMS = 200;

    const float KnotsToMPH = 1.15;



    int main( void ) {

    Storm* List[MAX_STORMS];

    Storm* CurrentStorm; // storm returned by GetStorm

    int NStorms = 0; // number in aray List

    int Total = 0; // total number of storms in the input file



    // replace with interactive version

    ifstream input("HurricaneTestFile.Data");



    // while we have storms to process

    while( (CurrentStorm = GetStorm( input ) ) != NULL ) {

    ++Total;

    if( CurrentStorm->category < 3 )

    delete CurrentStorm;

    else

    List[NStorms++] = CurrentStorm;

    }



    input.close();



    cout << "Number of storms: " << Total << endl;

    cout << "Hurricanes with category 3 and above: " << NStorms << endl;

    DisplayStorms("First Ten Storms", List, 10 );



    Sort( List, NStorms);

    DisplayStorms("Top Ten Storms", List, 10 );



    }



    int GetRecord( ifstream &in, int &year, int &month, int &day, int &hour,

    int &seq, char name[], int &wind, int &pres ) {

    // reads one "record" from the input, and stores in reference arguments

    // returns 0 if end-of-file, 1 if record read



    float junk;



    if (!(in.eof())) {

    in >> year >> month >> day >> hour >> seq >> name

    >> junk >> junk >> wind >> pres;

    return 1;

    }



    return 0;

    }



    Storm* GetStorm( ifstream& in ) {

    // Build a Storm structure, and return the poointer

    // static is necesary to save the last record read for

    // the next storm.



    static int year = 0, month, day, hour, seq, wind, pressure;

    static char name[15];

    static status = 1;

    int current, cat;

    Storm* NewStorm; // we'll return this pointer to the new storm object

    double mph;

    // If the last storm caused end-of-file, we're done.(return NULL)

    if( status == 0 )

    return NULL;



    // If this is the first time this function is called,

    // then read first record.

    if( year == 0 )

    GetRecord(in, year, month, day, hour, seq, name, wind, pressure);



    // Make a storm object and initialize it with info from the current record

    NewStorm = new Storm;

    NewStorm->beginDate = (year * 1000) + (month * 100) + day;

    NewStorm->duration = hour;

    strcpy(NewStorm->name, name);

    NewStorm->wind = wind;

    NewStorm->pressure = pressure;



    current = seq;



    // Now, keep reading records as long as they go with this storm.

    // Watch out for end-of-file!

    status = GetRecord(in, year, month, day, hour, seq, name, wind, pressure);

    while((strcmp(NewStorm->name, name) == 0) && (status == 1)) {

    //update storm info:

    NewStorm->duration += 6;

    if(NewStorm->wind < wind)

    NewStorm->wind = wind;

    if(((pressure < NewStorm->pressure) && pressure != 0) || NewStorm->pressure == 0 )

    NewStorm->pressure = pressure;

    cat = SaffirSimpson(NewStorm->wind);

    if(cat > NewStorm->category)

    NewStorm->category = cat;

    //get next record

    GetRecord(in, year, month, day, hour, seq, name, wind, pressure);

    }



    // convert from knots to mph

    NewStorm->wind *= KnotsToMPH;



    // and return the pointer to the new storm object:

    return NewStorm;

    }



    void PrintStorm( Storm* ptr ) {

    // display one storm

    cout >> ptr->beginDate >> ptr->duration >> ptr->name >> ptr->category

    >> ptr->wind >> ptr->pressure >> endl;



    return;

    }



    void DisplayStorms( char* title, Storm* List[], int NStorms ) {

    // display NStorms storms

    // print some title and column headings; make a loop

    // and invoke function "PrintStorm" for each storm.



    cout << "Begin Date" << setw(10) << "Duration (hours)" << "Name" << setw(10)

    << "Category" << "Maximum Winds (mph)"

    << "Minimum Pressure (mb)" << endl;

    cout << "----------------------------------------------------------------" << endl;

    for(int i = 0; i < NStorms; i++)

    PrintStorm(Storm* List);

    return;

    }



    int SaffirSimpson( int wind ) {

    // Compute storm category, using the Saffir-Simpson scale



    int category;



    if(wind > 134)

    category = 5;

    else if ((wind < 134) && (wind > 113))

    category = 4;

    else if ((wind < 113) && (wind > 96))

    category = 3;

    else if ((wind < 96) && (wind > 83))

    category = 2;

    else if ((wind < 83) && (wind > 64))

    category = 1;

    else if ((wind < 64) && (wind > 34))

    category = 'TS';

    else

    category = 'TD';



    return category;

    }



    void Sort( Storm* x[], int N ) {

    // bubble sort the list of Storm pointers

    int pass = 0, k, switches;

    Storm* temp;



    switches = 1;



    while( switches ) {

    switches = 0;

    pass++;

    for( k = 0; k < N - pass; k++ ) {

    if(x[k]->category < x[k + 1]->category) {

    temp = x[k];

    x[k] = x[k + 1];

    x[k + 1] = temp;

    switches = 1;

    }

    }

    }



    return;

    }

























    strauss.udel.edu% CC hurricane-starter.cc

    "hurricane-starter.cc", line 59: Warning: String literal converted to char* in formal argument title in call to DisplayStorms(char*, Storm**, int).

    "hurricane-starter.cc", line 62: Warning: String literal converted to char* in formal argument title in call to DisplayStorms(char*, Storm**, int).

    "hurricane-starter.cc", line 138: Error: The operation "std::basic_ostream<char, std::char_traits<char>> >> int" is illegal.

    "hurricane-starter.cc", line 154: Error: Unexpected type name "Storm" encountered.

    2 Error(s) and 2 Warning(s) detected.

    strauss.udel.edu% exit

  2. #2
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    Well, i tried compiling it in Turbo c++ and i got similar errors.

    do the following:

    on a cout, you're doing cout >> something
    it mus be cout << something (the arrows pointing to the other side)

    at some place you call

    PrintStorm(Storm* List);
    you should do
    PrintStorm(*List); //Without the Storm

    It compiled perfectly, but It didn't do anything, but you try this and see if it works!


    Good luck

    Oskilian

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21