Hi, newbie here. I'm working on a simple program having to do with mad libs. This is the code.
#include <iostream>
using namespace std;
int main()
{
char teacher_name, your_name, food, adjective, color, animal
;int number
;cout << "Welcome to Bad Excuse Generator!\n";
cout << "Enter the name of your instructor:\n";
cin >> teacher_name;
cout << "What's the last thing you've ate today?\n";
cin >> food;
;cout << "Enter a number between 100 and 120:\n";
cin >> number;
;cout << "Enter a creative adjective:\n";
cin >> adjective;
;cout << "Enter your favorite color:\n";
cin >> color;
;cout << "Enter an animal:\n";
cin >> animal;
;cout << "Dear Instructor";
cout << teacher_name
;cout << "I am sorry that I am unable to turn in my homework at this time. First, I ate a rotten";
cout << food
;cout << ",which caused me to turn";
cout << color
;cout << "and extremely ill. I came down with a fever of";
cout << number
;cout << ". Next, my";
cout << adjective
;cout << "pet";
cout << animal
;cout << "must have smelled the remains of the";
cout << food
;cout << "on my homework, because he ate it. I am currently rewriting my homework and hope you will accept it late.\n";
cout << "Sincerely,\n";
cout << your_name
cout << "In all seriousness, though, get off Facebook and do your homework.\n";
;return 0;
}
It works fine at first, but after entering the instructor's name, the program stops and this error message pops up:
Run-Time Check Failure #3 - The variable 'your_name' is being used without being initialized.
And then another tab opens and a code which is too long to put in this message appears. Here's the beginning of it:
/***
*crtexe.c - Initialization for console EXE using CRT DLL
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* This is the actual startup routine for apps linking to the CRT DLL.
* It calls the user's main routine [w]main() or [w]WinMain after
* performing C Run-Time Library initialization.
*
* With ifdefs, this source file also provides the source code for:
* wcrtexe.c the startup routine for console apps with wide chars
* crtexew.c the startup routine for Windows apps
* wcrtexew.c the startup routine for Windows apps with wide chars
*
*******************************************************************************/
#ifdef CRTDLL
/*
* SPECIAL BUILD MACROS! Note that crtexe.c (and crtexew.c) is linked in with
* the client's code. It does not go into crtdll.dll! Therefore, it must be
* built under the _DLL switch (like user code) and CRTDLL must be undefined.
* The symbol SPECIAL_CRTEXE is turned on to suppress the normal CRT DLL
* definition of _fmode and _commode using __declspec(dllexport). Otherwise
* this module would not be able to refer to both the local and DLL versions
* of these two variables.
*/
1. use code tags
2. declare variables that can store more than a single character
(optional)
3. learn some kind of input checking, e.g make sure that the user enters only integers between 100-120
4. rtfm, your compiler error messages are your responsibilities to learn and make sense of :P
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string teacher_name;
string your_name;
string food;
string adjec_1; //I put each Variable on a seperate line for clarifications sake.
string color;
string animal;
float number;
cout << "Welcome to Bad Excuse Generator!";
cout <<endl << "Enter the name of your instructor: -> ";
getline (cin, teacher_name);
cout <<endl << "What's the last thing you've ate today? -> ";
getline (cin, food);
cout <<endl << "Enter a number between 100 and 120: -> ";
cin >> number;
cout <<endl << "Enter a creative adjective: -> " ;
getline (cin, adjec_1);
cout <<endl << "Enter your favorite color: -> ";
getline (cin, color);
cout <<endl << "Enter an animal:- >";
getline (cin, animal);
cout << "Dear Instructor";
cout << teacher_name;
cout << "I am sorry that I am unable to turn in my homework at this time. First, I ate a rotten ";
cout << food;
cout << ",which caused me to turn";
cout << color;
cout << "and extremely ill. I came down with a fever of ";
cout << number;
cout << ". Next, my ";
cout << adjec_1;
cout << "pet ";
cout << animal;
cout << "must have smelled the remains of the ";
cout << food;
cout << "on my homework, because he ate it. I am currently rewriting my homework and hope you will accept it late.\n";
cout << "Sincerely,\n";
cout << your_name;
cout << endl << "In all seriousness, though, get off Facebook and do your homework.\n";
cout << endl << "Press enter to continue....";
cin.get();
return 0;
}
It should work in your compiler. I made a few changes as you can tell. Anyway, There are still some more problems, but Ill let you figure them out....