![]() |
Stuck on cin/cout
can someone tell me what i did wrong with this text? it seems simple enough to me, but for some reason, Dev-C++ refuses to compile it
#include <iostream> using namespace std; void main() { int age = 0; cout << "How old is your dog?" endl; cin age; cout << "Your dog is "; cout << age; cout << " years old!" endl; cin.get return 0; } Here are the errors i get : 'main' must return 'int', expected ';' before "endl" age endl and return statement cannot resolve address of overloaded function |
-You are missing << prior to both of your endl; statements.
-You are missing >> between cin and age. -You can put your output on one line, there is no need to split it out like you are doing. -Your return type of main is void, yet you return 0 at the end. The return type should be of type int. -Your errors within the compiler are pointing you in the right direction. You need to read up more on cin, cout, and the << and >> operators. -Next time, put your code in [ CODE ] yourcode [ /CODE ] tags. I'll let someone else elaborate on that, in the interim you can read the forum rules. This will work for you, if you have ANY questions. Ask... don't assume anything. :
#include <iostream>Executed: Quote:
|
Hmm, so by adding the
:
|
You don't need to assign a variable. Just use cin.get ();
Note that if previous operations leave material in the buffer, you will need to empty the buffer before the cin (regardless of the form you use). Note also that input buffers are not available until an end of line or end of file condition. Therefore, it is better to use "Press ENTER to continue" than "Press any key...". The latter requires non-portable code which is operating system and implementation dependent. Suggested reading: The FAQ/rules, the "How to Post a Question" thread, and the documentation for the functions you use. Bear in mind that it is important to test your input statements for success. I can break any of these examples with 2 keystrokes. |
Quote:
|
Some words of advice for debugging:
Start with the first error first. Often times, an error at the beginning of the program can trip false errors later on (especially when the initial mistake was improper placement of scope brackets. |
For that matter, the actual line number of the errors are not always exact. You will need to look a few lines above also.
|
| All times are GMT -5. The time now is 3:11 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC