Need help with this code

This is a discussion on Need help with this code within the C++ Programming forums, part of the General Programming Boards category; Need help with this program. I am new tpo programing and am not expereience in c++. Theanks for you hel ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    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;
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    What, exactly, are the errors?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21