|
There's no such thing as "meant to be executed from the console" except commands. Programs can be executed on the console. But note that I mainly develop in linux and compiling/running is usually done on the console (except for big projects, but even those!) so what I meant was, any output would still be in the console, even with the program's termination.
Just do what I said. It's post #70 in this thread. ![]() ![]() ![]() ![]() ![]() ![]() |
|
Exactly. I was correcting the guy who said "put cin.get()" at the end. Guess the quote boxes weren't clear
I don't even know the first thing to do.. ![]() ![]() ![]() ![]() ![]() ![]() |
|
You didn't do everything we said then. =|
If you're trying Dev-C++ (which is what I highly suggest currently as it gives the cleanest coding experience in Windows), just start a new file and call it "main.cpp". Copy and paste the code I showed you into the editor, save it and in the toolbars, there should be a "compile" and/or "run" button. Click on that button to run the file. Due to the fact that windows is weird, insert the code: "cin.get()" right before "return 0", otherwise, the console will automatically close and you won't see anything. To exit the program, just press enter. Note that the program is simply waiting for an input (cin.get()) before it executes "return 0" which closes the program. For now, just see if you can get that working. And tell us exactly what you did if you can't get it working. ![]() ![]() ![]() ![]() ![]() ![]() |
|
Do you have a .cpp file in the project? Copy and paste the following into it and then hit ctrl-F5.
Code#include <iostream> using namespace std; int main() { cout << "Hello, world!" << endl; return 0; } Try getting it to print different things. When you're bored of that, copy and paste this: Code#include <iostream> #include <string> using namespace std; int main() { string name; cout << "Enter your name:" << endl; cin >> name; cout << "Hello, " << name << "!" << endl; return 0; } And then from there, start reading: http://www.cplusplus.com/doc/tutorial/program_structure.html ![]() ![]() ![]() ![]() ![]() ![]() |
|
Remember the game! P.s.: Feldspar.
|
That said...if your console program is meant to be double-clicked from windows, adding Codesystem("pause"); before the return 0; is the right way to go. But this only works for windows.That's only if you want the ugly "Press any key to exit . . ." or whatever. |
|
That said...if your console program is meant to be double-clicked from windows, adding Codesystem("pause"); before the return 0; is the right way to go. But this only works for windows.That's only if you want the ugly "Press any key to exit . . ." or whatever. Codewhile (!kbhit()); remember to include conio.h (though mine has it in stdio.h also). |
|
The "alt + F5" didn't work. I opened my file "Project 1" and then went to the left side tree and clicked on the main.cpp file and then went to the right side and copy and pasted the code you provided, hit alt + F5 and nothing happened.
![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
You want a cin.get(); instead of a return 0; so the program remains open. This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever? Ctrl + F5 <3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google* ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
*shreds*
|
You want a cin.get(); instead of a return 0; so the program remains open. This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever? You don't want it to continue when you hit enter? Ctrl + F5 <3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google* Umm, that would be one HUGE list. Depends on what libraries you are using. ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
|
You want a cin.get(); instead of a return 0; so the program remains open. This only works once until you hit a key or type something in followed by the enter, then the message comes back up again. Is there some number that I am supposed to input into the "()" area to make it last forever? You don't want it to continue when you hit enter? Ctrl + F5 <3 YEAH! It worked! Now all that I have to do is learn some code that can actually be used for something decent and BAM! Is there a list somewheres that has every code with what it does? *Starts to Google* Umm, that would be one HUGE list. Depends on what libraries you are using. I want it to be able to stay open even after you enter commands, valid or not valid. I would just want a basic list of code so that I can familiarize myself with it. ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
Resident Spy
|
Code// While loop example #include <iostream> using namespace std; int main () { int a,b,c; a = 1; cout << "Go" "\n"; cin>> c; cin.ignore(); while (a==1) if (c==1) { cout << "Input a number to be cubed." "\n"; cin>> b; cout << b * b * b "\n"; cin.get(); cout << "Press 1 if you wish to go again" "\n"; cin>> c; cin.get(); } else if (c > 1, c < 1) { return 0; } } A quick program I made to demonstrate. ![]() ![]() ![]() ![]() ![]() ![]() |
|
I paid eleven minerals for THIS?
|
What is with C and using >> and << as syntax
Also, I assume that Code while (a==1) if (c==1) { cout << "Input a number to be cubed." "\n"; cin>> b; cout << b * b * b "\n"; cin.get(); cout << "Press 1 if you wish to go again" "\n"; cin>> c; cin.get(); } else if (c > 1, c < 1) { return 0; } is equivalent to Code while (a==1) { if (c==1) { cout << "Input a number to be cubed." "\n"; cin>> b; cout << b * b * b "\n"; cin.get(); cout << "Press 1 if you wish to go again" "\n"; cin>> c; cin.get(); } else if (c > 1, c < 1) { return 0; } } ...but I hate lazy syntax. ![]() ![]() ![]() ![]() ![]() ![]() "Three can keep a secret, if two are dead." -Benjamin Franklin
"Had, having, and in quest to have, extreme; A bliss in proof, and proved, a very woe; Before, a joy proposed; behind, a dream. All this the world well knows; yet none knows well To shun the heaven that leads men to this hell." -William Shakespeare |
|
------ Build started: Project: Calculator, Configuration: Debug Win32 ------
Compiling... main.cpp c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(20) : error C2143: syntax error : missing ';' before 'string' c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(30) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\admin\my documents\visual studio 2008\projects\calculator\calculator\main.cpp(8)' was matched Build log was saved at "file://c:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\Calculator\Calculator\Debug\BuildLog.htm" Calculator - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== "There are build errors..." ![]() ![]() ![]() ![]() ![]() ![]() ╔═══╦═══╦═══╦══╦═╦═══╦═══╦═══╦═╦═╦═══╦═══╗
╠═══╣....═╣..═..║........╠╗..╔╣..═..╠═══╬╗..╔╩╗..╔╬═══╣ ╚═══╩═╩═╩═══╩═╩══╩╩═╩╩═══╩═══╩╩═╩═╩═╩╩═══╝ |
|
Line 20
Codecout << b * b * b "\n"; should be replaced with this: Codecout << b * b * b << "\n"; EDIT: Forgot to include the fix to the other error message. You need a closing brace "}" for the main() function, which you probably deleted by accident somehow. This post was edited 1 time, last edit by Epsilonite: May 25 2008, 6:03 am.
![]() ![]() ![]() ![]() ![]() ![]() |