Join 149,376 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,625 people online right now. Registration is fast and FREE... Join Now!
Ok, so I did this assignment using strictly STRINGS, however....unfortunately upon re-reading what I must do, I need to change the String to a C-string. I have already poured a good amount of effort and time finishing this program
In short my question is this: Is there any easy way to take my code below, and transpose all of the string elements to c-strings without drastically changing the program? And if so, how would I go about it? As always any and all help is greatly appreciated
char word_hint[3][3] = { //Hint 2-D Array { "BLANK Riding Hood", "Color of grass", "The night sky"}, { "Color of the sky", "Color of Big Bird", "Color for girls"}, { "Color of basketball", "The band Deep BLANK", "The color of nothing"}, };
word = word_array[pick_word1][pick_word2]; //Randomly selects word from 2-D Array & Stores in char var scrambled_word = word_array[pick_word1][pick_word2]; x = scrambled_word.length();
for ( int y = x; y > 0; y-- ){ //Swaping loop swap( scrambled_word[rand()%x],scrambled_word[y-1] ); }//end for
do{ cout << "The word that you must unscramble is: " << scrambled_word << endl; cout << "Go ahead and enter the word, type exit to leave, or hint for a Hint"<<endl; cin >> attempt;
if ( attempt == word ){ cout << "Congratulations! You got it correct!"<<endl; cout << "It took you " << num_attempts << " tries"<<endl; break; }//end if
if ( attempt != word && attempt !="hint" ){ cout << "Nope, try again" <<endl <<endl; num_attempts++; }//end if
if ( attempt == "exit" ){ cout << "Thanks for playing!"<<endl; break; }//end if
if ( attempt == "hint" ){ cout << word_hint[pick_word1][pick_word2]<<endl <<endl; }//end if
// Create an array of string pointers to hints char *word_hint[3][3] = { //Hint 2-D Array { "BLANK Riding Hood", "Color of grass", "The night sky"}, { "Color of the sky", "Color of Big Bird", "Color for girls"}, { "Color of basketball", "The band Deep BLANK", "The color of nothing"} };
// Copy the word and scrambled word via C-string copy strcpy(word,word_array[pick_word1][pick_word2]); //Randomly selects word from 2-D Array & Stores in char var strcpy(scrambled_word,word_array[pick_word1][pick_word2]);
// Not in Kansas anymore Toto... string.length is out, strlen is in! x = (int) strlen(scrambled_word);
for ( int y = x; y > 0; y-- ){ //Swaping loop swap( scrambled_word[rand()%x],scrambled_word[y-1] ); }//end for
do { cout << "The word that you must unscramble is: " << scrambled_word << endl; cout << "Go ahead and enter the word, type exit to leave, or hint for a Hint"<<endl; cin >> attempt;
// Strcmp is where it is at for comparing C-strings if ( strcmp(attempt,word) == 0 ){ cout << "Congratulations! You got it correct!"<<endl; cout << "It took you " << num_attempts << " tries"<<endl; break; }//end if
if ( strcmp(attempt,word) != 0 && strcmp(attempt,"hint") != 0 ){ cout << "Nope, try again" <<endl <<endl; num_attempts++; }//end if
if ( strcmp(attempt,"exit") == 0 ){ cout << "Thanks for playing!"<<endl; break; }//end if
if ( strcmp(attempt,"hint") == 0 ){ cout << word_hint[pick_word1][pick_word2]<<endl <<endl; }//end if
}while ( strcmp(attempt,word) != 0 );
system("PAUSE"); return EXIT_SUCCESS; }
Next time you have a problem that keeps you up at night, call on your experts at DIC to solve the toughest problems. We will have an expert on it same day, accurate quotes, superb job and great service! We work weekdays, weekends, even during the holidays. You can't beat the incredible service! Now remember, *music* Whennnnn you need a geek, and you can't sleeeeeep, don't be a noobie... Call 1....800... ASK .... D...I...C...C! *music*
Next time you have a problem that keeps you up at night, call on your experts at DIC to solve the toughest problems. We will have an expert on it same day, accurate quotes, superb job and great service! We work weekdays, weekends, even during the holidays. You can't beat the incredible service! Now remember, *music* Whennnnn you need a geek, and you can't sleeeeeep, don't be a noobie... Call 1....800... ASK .... D...I...C...C! *music*
Next time you have a problem that keeps you up at night, call on your experts at DIC to solve the toughest problems. We will have an expert on it same day, accurate quotes, superb job and great service! We work weekdays, weekends, even during the holidays. You can't beat the incredible service! Now remember, *music* Whennnnn you need a geek, and you can't sleeeeeep, don't be a noobie... Call 1....800... ASK .... D...I...C...C! *music*
Thank you so much Martyr2, and if I do say so myself that is quite the commercial jingle.
A potential plot if you will for the commercial:
Imagine some kid who is hopelessly lost on his code, cursing and yelling when all of a sudden a blazing guitar solo starts and excessive explosions follow. Then the camera pans to a shot of Gary Buesy who is totally pissed off and yelling furiously at everyone about absolutley nothing.
Camera pans back to the kid and 5 DIC members who assemble themselves into a mechanical dinosaur of sorts. Finally, Jeff Goldbloom gives a speech on Chaos Theory.
Thank you so much Martyr2, and if I do say so myself that is quite the commercial jingle.
A potential plot if you will for the commercial:
Imagine some kid who is hopelessly lost on his code, cursing and yelling when all of a sudden a blazing guitar solo starts and excessive explosions follow. Then the camera pans to a shot of Gary Buesy who is totally pissed off and yelling furiously at everyone about absolutley nothing.
Camera pans back to the kid and 5 DIC members who assemble themselves into a mechanical dinosaur of sorts. Finally, Jeff Goldbloom gives a speech on Chaos Theory.
End Result: Happy kid, finished code
Proposed Budget: $80,000,000
Let me know what you guys think!
Commercial idea has now been patented! Skyhawk, sloth, Psycho, Capty, and Amadeus have been cast in the role of the mechanical dinosaur. Jeff Goldbloom wasn't available, so I have casted myself as the speech giver, Penny is casted as Gary Buesy and special guest Axel is making a cameo by playing "the hopelessly lost kid".
Thanks for the idea! Look for it to be shown on all the cool channels... Food network, Women's network, and TLC. Now if those other guys... (ABC, NBC, CBS and Fox) want a piece of our kick ass commercial, they are going to have to pay!
Commercial idea has now been patented! Skyhawk, sloth, Psycho, Capty, and Amadeus have been cast in the role of the mechanical dinosaur. Jeff Goldbloom wasn't available, so I have casted myself as the speech giver, Penny is casted as Gary Buesy and special guest Axel is making a cameo by playing "the hopelessly lost kid".
Thanks for the idea! Look for it to be shown on all the cool channels... Food network, Women's network, and TLC. Now if those other guys... (ABC, NBC, CBS and Fox) want a piece of our kick ass commercial, they are going to have to pay!
[/quote]
Hahaha DIC FTW! If you're gonna put it on Food Network, see if Alton Brown from Good Eats wants to be cast as the rival dinosaur. Thanks again for all of your help Martyr2!