Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Lv 55,827 points

cppdummy

Favorite Answers10%
Answers1,574
  • C++ switch not working? What did I do wrong?

    do{

    int ALIVE=50000;

    char ch=0;

    ch = getche();

    switch(ch){

    case 1:

    printf ("Case 1:");

    break;

    case 2:

    printf ("Case 2:");

    break;

    case 3:

    printf ("Case 3:");

    break;

    case 4:

    printf ("Case 4:");

    break;

    case 6:

    printf ("Case 6:");

    break;

    case 7:

    printf ("Case 7:");

    break;

    case 8:

    printf ("Case 8:");

    break;

    case 9:

    printf ("Case 9:");

    break;

    default:

    cout << "in default" << endl;

    }

    } while (ALIVE==50000);

    3 AnswersProgramming & Design9 years ago
  • C++ Problem (Trying to split a string)?

    I am trying to use getline,cin to receive a two word string, and then split the string into two one word strings, must the same way the old text adventures of the 1980's did. However, I can't seem to figure it out. It should look like this:

    What shall I do? GO WEST

    Main reports that you typed

    go for a verb.

    west for the noun.

    My result is

    Main reports that you typed

    for a verb.

    go west for the noun.

    This is the intended code.

    int main(int argc, char *argv[])

    {

    while (death>0){

    string answer,verb,noun,separator;

    cout << "What shall I do? ";

    getline (cin,answer);

    for(unsigned int i=0;i<answer.length();i++){ // Convert to Lowercase

    answer[i] = tolower(answer[i]);}

    // Split answer in 2 variables

    size_t i = answer.find(separator);

    if(i != string::npos){

    size_t y = 0;

    if(!answer.empty()){

    while(y != i){

    verb += answer[y++];

    }

    y+= separator.length();

    while(y != answer.length()){

    noun+=answer[y++]; //creating noun string

    }

    }

    cout << "Main reports that you typed " << endl;

    cout << verb << " for a verb." << endl;

    cout << noun << " for the noun.\n\n" << endl;

    }

    Any help would be appreciated.

    system("PAUSE");

    return EXIT_SUCCESS;

    }

    }

    2 AnswersProgramming & Design9 years ago
  • C++ reading text files into a class?

    Text file: (short version)

    "Garden",0,0,0,2,0,0,0,0,0,0,10,0,"You are now inside the garden. Exits are to the west."

    "North area",0,3,1,0,0,0,0,0,0,0,10,0,"You are in a large open area surrounded by shade trees. Exits are south and east."

    "South area",2,0,0,0,0,0,0,0,0,0,10,0,"You are standing on a sidewalk. An exit lies to the north."

    H file, holding the class

    [code]

    #ifndef __ROOMS_H__

    #define __ROOMS_H__

    class rooms

    {

    public:

    rooms(){};

    ~rooms(){};

    string getname(){return name;}

    string getdesc(){return desc;}

    int getnorth(){return north;}

    int getsouth(){return south;}

    int geteast(){return east;}

    int getwest(){return west;}

    int getnortheast(){return northeast;}

    int getsoutheast(){return southeast;}

    int getnorthwest(){return northwest;}

    int getsouthwest(){return southwest;}

    int getup(){return up;}

    int getdown(){return down;}

    int getaolight(){return aolight;}

    int gettrap(){return aotrap;}

    protected:

    string name;

    string desc;

    int north;

    int south;

    int east;

    int west;

    int northeast;

    int southeast;

    int northwest;

    int southwest;

    int up;

    int down;

    int aolight;

    int aotrap;

    };

    class idvroom : public rooms

    {

    public:

    idvroom(string _name="",string _desc="",int _north=0,int _south=0,int _east=0,int _west=0,int _northeast=0,int _northwest=0,int _southeast=0,int _southwest=0,int _up=0,int _down=0,int _aolight=0,int _aotrap=0)

    {name=_name;desc=_desc;north=_north;south=_south;east=_east;west=_west;northeast=_northeast;northwest=_northwest;southeast=_southeast;southwest=_southwest;up=_up,down=_down,aolight=_aolight;aotrap=_aotrap;};

    ~idvroom(){};

    };

    #endif [/code]

    What is the best way to read the text file and it's values into the class ? Descriptions, and values will change, so it can't be static...

    2 AnswersProgramming & Design1 decade ago
  • Is there a better way to do this?

    This is a sample of an array. I want to condense it, and load everything back into the original array with the empty slots at the end. Maybe a class instead of an array, or another suggestion?

    #include <cstdlib>

    #include <iostream>

    #include <string>

    using namespace std;

    int itembackup[12];

    string itemsbackup[12];

    int main(int argc, char *argv[])

    {

    int item[12]={5,3,0,19,0,4,0,10,9,0,0,0};

    string items[12]={"rue","ama","nothing in this slot","cloak","nothing in this slot","sceptre of death","nothing in this slot","zar","staff","nothing in this slot","nothing in this slot","nothing in this slot"};

    int itembackup[12]={0,0,0,0,0,0,0,0,0,0,0,0}…

    string itemsbackup[12]={"","","","","","","",""…

    cout << "Initial list for 12 slots.\n\nSlot number\tItem value\t\tItem name" << endl;

    for (int x=0;x<11;x++){cout << x <<"\t\t"<< item[x] << "\t\t\t" << items[x] << endl;}

    cout << "\n" << endl;

    //copy list to backup, and clear original

    for (int x=0;x<11;x++){itembackup[x]=item[x];item…

    //Reload original array, placing all items to brginning, no blanks.

    int y=0;

    for (int x=0;x<11;x++){

    if (itembackup[x]>0){

    item[y]=itembackup[x];items[y]=itemsback…

    y++;}

    for (int con=y;con<11;con++){item[con]=0;items[co… here.";}}

    cout << "Final list for 12 slots.\n\nSlot number\tItem Value\t\tItem name" << endl;

    for (int x=0;x<11;x++){cout << x <<"\t\t"<< item[x] << "\t\t\t" << items[x] << endl;}

    system("PAUSE");

    return EXIT_SUCCESS;

    }

    2 AnswersProgramming & Design1 decade ago
  • Is it possible...to love more than one person ar a time?

    I'm, usually known for my cut to the quick, sharp tongue, no bullshit opinions. I usually have an answer for anything, after all, if you advise someone the to do what's right, you can't go wrong. But I got buffaloed the other day. I was talking with a girl where I work and she was telling me about her dating two guys. Both guys know about each other (Thanks to my advice to her) everything is on the up and up. She said she had to make a choice between them but couldn't decide. She posed this question to me. "Is it possible to be in love with more than one person at the same time."

    My initial reaction was to think "Hell no", after all, if you love someone truly, there can't be love for someone else. It's not possible.

    Then it hit me that as a parent, I love all six of my children equally... So it is possible.

    I can see both sides of the coin. I told her I'd think about it, and get back to her. I have no clue as to how I'm going to answer her. So Yahoo... I put it to you. Is it possible?

    4 AnswersOther - Family & Relationships1 decade ago
  • C++ Class (Help a brother out)?

    I wrote a class in c++, and I have an array of data. I am trying to get the class to except the array, but am having a terrible time. The only way I can get it to work, is if I put the actual array in main function, of the main.cpp file. I want it try to keep the array in the monster.h file and then assign whatever monster I am using at the time, a more manageable variable name. So instead of

    mon[53].name, or mon[69].desc, I would be able to use something like critter.name and critter.desc... Can someone give me a clue as to what I'm doing wrong here?

    Monster.h

    #ifndef __MONSTER_H__

    #define __MONSTER_H__

    #include <ctime>

    #include <string>

    #include <iostream>

    class monster

    {

    public:

    monster(){};

    ~monster(){};

    string name;

    int lvl;

    int ac;

    int gend;

    int maxdam;

    int gold;

    int hits;

    int exp;

    string wep;

    int wepdam;

    string desc;

    string getname(){return name;}

    int getlvl(){return lvl;}

    int getac(){return ac;}

    int getgend(){return gend;}

    int getmaxdam(){return maxdam;}

    int getgold(){return gold;}

    int gethits(){return hits;}

    int getexp(){return exp;}

    string getwep(){return wep;}

    int getwepdam(){return wepdam;}

    string getdesc(){return desc;}

    };

    class npc:public monster

    {

    public:

    npc(string _name="", int _lvl=0, int _ac=0, int _gend=0, int _maxdam=0, int _gold=0, int _hits=0, int _exp=0, string _wep=0, int _wepdam="", string _desc="")

    {name=_name;

    lvl=_lvl;

    ac=_ac;

    gend=_gend;

    maxdam=_maxdam;

    gold=_gold;

    hits=_hits;

    exp=_exp;

    wep=_wep;

    wepdam=_wepdam;

    desc=_desc;

    }

    };

    #endif

    The data array goes like this:

    mon[0]=npc("name",1,0,0,5,10,6,5,"wep name",2,"mons description.");

    mon[1]=npc("name",1,0,0,5,10,6,5,"wep name",2,"mons description.");

    mon[2]=npc("name",1,0,0,5,10,6,5,"wep name",2,"mons description.");

    mon[3]=npc("name",1,0,0,5,10,6,5,"wep name",2,"mons description.");

    mon[4]=npc("name",1,0,0,5,10,6,5,"wep name",2,"mons description.");

    and so on up to

    mon[299]=npc("name",1,0,0,5,10,6,5,"we… name",2,"mons description.");

    3 AnswersProgramming & Design1 decade ago