I AM SUFFERING SO HARD PLEASE HELP ME MAKE A CODE THAT WILL NOT HAVE AN ERROR CO
ID: 3541379 • Letter: I
Question
I AM SUFFERING SO HARD PLEASE HELP ME MAKE A CODE THAT WILL NOT HAVE AN ERROR COME OUT! I Have made multiple mad libs, but my coding must be off. Any example would help. Nothing to complex- You must have at least 1 of each of the following C datatypes:
int,double, andchar - You must have at least 2 null terminated character arrays (strings) that are used for user input.
- Your program will prompt the user for the different data (search for mad libs online for examples) and then display the full mad lib.
Hint and Tips
- doubles must be input using %ld scanf specifier
- You can declare a separate string to act as your story template, e.g.:
char story_templ[] = "%d fish, %f fish, %s fish, %s fish "; - You may spread a string initialization across multiple lines using the following trick:
char my_long_string[] = "Twas brillig in the slithy toves,"
"Did gyre and gimble in the wabe. "
"All mimsy were the borogoves "
"And the momeraths outgrabe. ";
Explanation / Answer
If you're using Python 2, try:
adj1 = raw_input('Type in an adjective: ')
raw_input() is a function that returns the stdin as a string. input(), however, evaluates the code first, meaning it treats it as code. To see what I mean, try this experiment:
smelly = 7
adj1 = str(input('Type in an adjective: ')) # Type in "smelly" without the quotes
print(adj1)
This program will print "7". This is because the interpreter evaluates your text as a variable name which is a reference to the int 7. Then it turns 7 into a string and prints it. But raw_input() doesn't try to evaluate the code first.
In Python 3, input() does what raw_input() did in Python 2. To get Python 2's input() behavior in Python 3, you say eval(input()).
#include <iostream>
using namespace std;
int main(){
bool playagain = true;
while(playagain == true){
char* noun;
char* adjective;
cout << "Enter a noun:";
cin >> noun;
cout << "Enter an adjective:";
cin >> adjective;
cout << "You're not very " << adjective << " if you like to play with " << noun << "s." << endl;
char playagainchar;
cout << "Play again? (y or n): ";
cin >>playagainchar;
if(playagainchar != 'y') playagain = false;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.