String method crashes program...

Posted by TimothyTech on Stack Overflow See other posts from Stack Overflow or by TimothyTech
Published on 2010-06-18T16:36:16Z Indexed on 2010/06/18 16:43 UTC
Read the original article Hit count: 359

Filed under:
|

Alright so i have two identical string methods...

string CreateCust() { 
    string nameArray[] ={"Tom","Timo","Sally","Kelly","Bob","Thomas","Samantha","Maria"};
    int d = rand() % (8 - 1 + 1) + 1;   
    string e =  nameArray[d];
    return e;
   }      

string CreateFood()  {
     string nameArray[] = {"spagetti", "ChickenSoup", "Menudo"};
     int d = rand() % (3 - 1 + 1) + 1;   
     string f =  nameArray[d];
     return f;
} 

however no matter what i do it the guts of CreateFood it will always crash. i created a test chassis for it and it always fails at the cMeal = CreateFood();

        Customer Cnow;        
        cout << "test1" << endl;
        cMeal = Cnow.CreateFood();
        cout << "test1" << endl;
        cCustomer = Cnow.CreateCust();
        cout << "test1" << endl;

i even switched CreateCust with CreateFood and it still fails at the CreateFood Function...

NOTE: if i make createFood a int method it does work...

© Stack Overflow or respective owner

Related posts about c++

Related posts about class