-
Need help with this code
Need help with this program. I am new tpo programing and am not expereience in c++. Theanks for you hel I understand there are lots of errors but don tknow how to fix them.
The Purpose of this code is to create a mad lib
Code:
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
cout << "Enter in words each word with one space in between;" <<endl;
cout << endl;
string onesName;
cout << "Enter your first name; ";
cin >> onesName;
cin.ignore(99,'\n');
string famousPerson;
cout << "Enter the name of famous person; ";
cin >> famousPerson;
cin.ignore(99,'\n');
string animalInput;
cout<< "Enter an animal; ";
cin >> animalInput;
cin.ignore(99,'\n');
string numberInput;
cout << "Enter a number, one digit only; ";
cin >> numberInput;
cin.ignore(99,'\n');
string emotionInput;
cout << "Enter an emotion; ";
cin >> emotionInput;
cin.ignore(99,'\n');
string adjectiveInput;
cout << "Enter an adjective; ";
cin >> adjectiveInput;
cin.ignore(99,'\n');
// this is processing:
string dear = "Dear, " + onesName + '!';
string seconline = "I wanted to inforn you the" + famousePerson + 'received your letter.';
string thirdline = "We just wanted to tell you that he does not have your" + animalInput + '!';
string fourthline = " But we will gladly donate" + numberInput + 'for your cause.';
string fifthline = "We are sorry and hope you have a" + emotionInput + 'day.';
string lastline = "Your" + adjectiveInput + 'friend, Jesus G.';
// this is output:
cout << dear << endl;
cout << secondline << endl;
cout << thirdline << endl;
cout << fourthline << endl;
cout << fifthline << endl;
cout << endl;
cout << lastline << endl;
cout << endl;
// endgame
cout << endl << "ENTER to finish...";
cin.ignore(99,'\n');
return 0;
}
-
What, exactly, are the errors?
-
Well, the errors are
Code:
Comeau C/C++ 4.3.10.1 (Oct 6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ C++0x_extensions
"ComeauTest.c", line 46: error: identifier "famousePerson" is undefined
string seconline = "I wanted to inforn you the" + famousePerson + 'received your letter.';
^
Simple typo.
Code:
"ComeauTest.c", line 46: error: too many characters in character constant
string seconline = "I wanted to inforn you the" + famousePerson + 'received your letter.';
^
"ComeauTest.c", line 48: error: too many characters in character constant
string fourthline = " But we will gladly donate" + numberInput + 'for your cause.';
^
"ComeauTest.c", line 49: warning: multicharacter character literal (potential
portability problem)
string fifthline = "We are sorry and hope you have a" + emotionInput + 'day.';
^
"ComeauTest.c", line 49: error: no operator "+" matches these operands
operand types are: std::basic_string<char, std::char_traits<char>,
std::allocator<char>> + int
string fifthline = "We are sorry and hope you have a" + emotionInput + 'day.';
^
"ComeauTest.c", line 50: error: too many characters in character constant
string lastline = "Your" + adjectiveInput + 'friend, Jesus G.';
Single quotes are for characters, double quotes are for string literals. ^
Code:
"ComeauTest.c", line 55: error: identifier "secondline" is undefined
cout << secondline << endl;
Another simple typo.