I need help with this game of mine please urgent!!!

Ok so I'm new to here but I'm trying to make a game for my project at school the game is going really well but I can't get the input(cin) right when I ask the user to pick a character it works fine but will output the information after the user types the characters name twice i need to resolve this please the deadline is tomorrow also it would help if you told me where I went wrong so I can learn from my mistake here is my games code :

[*Code]
#include <iostream>
#include <string>
using namespace std;

int main(){

cout <<"***********Pick a side*************"<< endl;
cout << "1) Team A \n"
"2) Team B \n"
"3) Team C \n"
"4) Team D \n"
"5) Team E \n"
"6) Team F \n"
" \t (Press a team's letter to pick)" << endl;

char answer;
cin >> answer;
cout <<"***********************************************************"<<endl;
switch(answer){

case 'A': case 'a':cout<< "You've Picked A!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Saitama = 6,000,980,000\n"
"2 = Goku = 7,300,000,000\n"
"3 = Ken-kenaki = 750,000,000 (as a ghoul)\n"
"4 = Gray = 5,000,000,000\n"
"5 = Ichigo = 4,000,500,000\n"
"6 =(Pick one) Eto,Touka and Ayato = 2,000,500,000 (all together)\n\n"
"====================================================================\n\n";
break;

case 'B': case 'b': cout<<"You've picked B!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Sasuke(Adult) = 7,000,970,000\n"
"2 = Naruto(Hokage) = 8,000,500,000\n"
"3 = Luffy = 6,000,670,000\n"
"4 = Genos = 4,000,435,000\n"
"5 = Natsu = 5,000,456,000\n";
break;

case 'C': case 'c': cout<<"You've picked C!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Kirito w/ Yui = 2,000,970,000\n"
"2 = Edward Elric = 5,000,500,000\n"
"3 = Light Yagami = 6,000,670,000\n"
"4 = Bukugo = 4,000,435,000\n"
"5 = Gohan = 5,000,456,000\n";
break;

case 'd': case 'D': cout<<"You've picked D!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Eren and Mikasa = 2,000,000,000\n"
"2 = Vegeta = 6,000,500,000\n"
"3 = Madara,Hashirama and senjurama = 8,000,670,000\n"
"4 = Zorro and Ace = 7,000,435,000\n"
"5 = Soul evans = 6,000,456,000\n";
break;

case 'E': case 'e': cout<<"You've picked E!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Mob = 200,970,000\n"
"2 = X Burner Tsuna = 100,500,000\n"
"3 = Asta= 2,000,670,000\n"
"4 = Alucard = 4,000,435,000\n"
"5 = Accelerator = 4,000,456,000\n";
break;

case 'F': case 'f':cout<<"You've picked F!,here are the members of the guild:\n\n"

"Characters: Power Levels:\n\n"

"1 = Kirito w/ Yui = 2,000,970,000\n"
"2 = Zeno = 8,000,500,000\n"
"3 = Kaguya = 6,000,670,000\n"
"4 = Meliodas = 4,000,435,000\n"
"5 = Kenpachi = 5,000,456,000\n";
break;

default: cout<< "No specific character was chosen, the program will now end!!"<<endl;
}

cout<< "Choose a Character to play with by typing first name\n"<<endl;
string anime_Character;
string goku_Dbz;
string kenaki;

getline(cin,anime_Character);
getline(cin,goku_Dbz);
getline(cin,kenaki);






if (anime_Character == "Saitama")
{
cout <<"Nice Choice, You chose Saitama here is his abilities, stats and info:\n\n"


"Alias :Caped Baldy (ハゲマント, Hagemanto)\n\n"
"Sensei (先生, Sensei) (by Genos)\n\n"
"Master (by Genos)\n\n"

"Health : 7000/7000\n\n"
"Race : Human\n\n"
"Age : 25\n\n"
"Height : 175 cm (5'9)[2]\n\n"
"Weight : 70 kg (154 lbs.)[2]\n\n"
"Location : Z-City, Saitama's Apartment\n\n"
"Abilities :Immeasurable Physical Prowess, Supernatural Senses, Invulnerability, Indomitable Will\n\n"
"Status : Alive\n\n"
"Occupation : Hero,Sensei\n\n"
"Level : B-Class (Manga)\n\n"
"Rank : 7 (Manga)\n\n"
"Affiliation : Hero Association, Saitama Group\n\n"
"Partner(s): Genos (Disciple)\n\n"

"More Info: Saitama (サイタマ, Saitama) is the main protagonist of One-Punch Man and so far the most powerful hero alive in the series. Saitama faces a self-imposed existential crisis, as he is now too powerful to gain any thrill from his deeds.[3]\n\n"

"Initially just a hero for fun,[4] he later registers into the Hero Association as a professional hero,[5] currently B-Class Rank 7,[6] and defends his home in Z-City from Mysterious Beings.[7] Under the Hero Association, he is given the name Caped Baldy (ハゲマント, Hagemanto; Viz: Bald Cape).[8]";

}else if(goku_Dbz == "Goku" || goku_Dbz == "goku"){

cout<<"Well picked!! Goku is strong enough talking here is his abilites, stats and info:\n\n"

"Health = 8000/8000\n\n"
"Race = Saiyan \n\n"
"Gender = Male\n\n"
"Date of birth = Age 736,Age 737(anime)\n\n"
"Date of death = October 12, Age 761\n\n(revived on November 2, Age 762)\n\n"
"(May 26, Age 767)\n\n(revived on May 8, Age 774)\n\nAge 779 (altered history; time reversed, death undone)\n\n"

"Height = 5'9 (175 cm) (*adult*)\n\n"
"Weight = 136 lbs (62 kg) (*adult*)\n\n"
"Address = 439 East District\n\n"
"Occupation = Martial Artist Firefighter \n\n" "(Goku's Fire Brigrade)" "Farmer\n\n"
"Security Guard\n\n"
"Allegiance = Dragon Team\n\n"
"Turtle School (formerly)\n\n"
"Team Universe 7\n\n"
"Time Patrol\n\n"


"More info:\n\n";

cout << "Son Goku (孫そん悟ご空くう Son Gokū), born Kakarot (カカロット Kakarotto), is a male Saiyan and the main protagonist of the Dragon Ball series.\n\nGoku is a Saiyan originally sent to Earth as an infant with the mission to destroy it, an accident alters his memory.\n\nallowing him to grow up to become Earth's greatest defender, as well as the informal leader of the Dragon Team.\n\nThroughout his life, he constantly strives and trains to be the greatest warrior possible and to fight stronger opponents, which has kept the Earth and the universe safe from destruction many times."<< endl;

}else if(kenaki == "kenaki"|| kenaki == "Kenaki"){

cout <<"You have Chosen Kenaki!! here is his abilites and info:\n\n"<<endl; }







return 0;

}
[\Code]
In order for it to say you chosen kenaki!! you have to type it twice I want the user to type once to work Thanks -- Programmer X
Last edited on
Edit your post (bottom-right corner) and add [code] and [/code] tags so that your code is more pleasant to look at.

but will output the information after the user types the characters name twice
Did you write this code? You are calling getline 3x times. It sounds like you want the player to type in 1 name, so why do you call getline 3 times? The other problem is that mixing getline and cin can lead to some weird behavior when newlines are kept in cin's buffer.

Add a cin.ignore() before your calls to getline to remove the newline.
1
2
cin.ignore()
getline(cin,anime_Character);

Then, compare anime_Character to "kenaki" or "Goku", or whatever.
Last edited on
Could you tell me how to write it I'm not too sure I'm new to c++ Thanks for the reply.
Step one is to edit your OP post like I said, by formatting your code. Step two is to remove the multiple getline calls and just have the cin.ignore(); followed by getline(cin, anime_Character).

Then, instead of checking if goku_Dbz == "Goku", have anime_Character == "Goku"

http://www.cplusplus.com/doc/tutorial/
http://www.cplusplus.com/doc/tutorial/control/ <-- read about if-statements.
So should i write
cin.ignore();
getline(cin,anime_Character);
keep doing it for the rest? and please i don't want to bother you but what do you mean OP post im scratching my head all over it Thank you you helping me alot!!!
Last edited on
I meant your first post. Go to the "Edit" button at the bottom of it, and add [code] before the start of your code, and [/code] after your code ends, so that your code gets formatted correctly.

Read the tutorial on control I posted, and try to fix your code, and if you still can't figure it out, post what you tried.
It seemed to work Thanks your a lifesaver i can't thank you more not in a million years would i be able to have solved that without you guidance and help Thanks for everything!!!!
Any use of cin is subject to errors that need to be handled to prevent the infinite output loop.

Visit the official website of Kizi Games http://www.kizifan.com/ the creator of your favorite games like 1010! and 1010! World
Last edited on
Topic archived. No new replies allowed.