Programing
May 20 2008, 11:48 pm
By: Brontobyte
Pages: < 1 « 3 4 5 6 7 >
 

May 23 2008, 12:23 am Brontobyte Post #81



I don't even know the first thing to do..

How do I "compile" my source code into a program? Can I do it through the C++ program or do I need to download more stuff?

Post has been edited 1 time(s), last time on May 23 2008, 12:31 am by Brontobyte.



None.

May 23 2008, 12:31 am cheeze Post #82



Quote
No. Your program shouldn't need to do this. Console programs are meant to be executed from the console, and as such, the output should still be on the screen.
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.

Quote
I don't even know the first thing to do..
Just do what I said. It's post #70 in this thread.



None.

May 23 2008, 1:19 am Heimdal Post #83



Quote from cheeze
Quote
No. Your program shouldn't need to do this. Console programs are meant to be executed from the console, and as such, the output should still be on the screen.
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.
Exactly. I was correcting the guy who said "put cin.get()" at the end. Guess the quote boxes weren't clear :)
Quote
Quote
I don't even know the first thing to do..
Just do what I said. It's post #70 in this thread.
Or follow my instructions in post #75. When you're ready to run your code, press ctrl-F5. or Debug->Start without debugging.



None.

May 23 2008, 6:52 pm Brontobyte Post #84



I did that and then what do I do? How do I see a preview of what I just worked on? What do I type to start? I have so many questions...



None.

May 23 2008, 7:10 pm cheeze Post #85



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.



None.

May 23 2008, 7:16 pm Heimdal Post #86



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



None.

May 23 2008, 8:47 pm O)FaRTy1billion[MM] Post #87

👻 👾 👽 💪

Quote from Heimdal
That said...if your console program is meant to be double-clicked from windows, adding
Code
system("pause");
before the return 0; is the right way to go. But this only works for windows.
Gross.
That's only if you want the ugly "Press any key to exit . . ." or whatever.



TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB - topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig - topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
\:farty\: This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!

May 23 2008, 9:29 pm Doodle77 Post #88



Quote from O)FaRTy1billion[MM]
Quote from Heimdal
That said...if your console program is meant to be double-clicked from windows, adding
Code
system("pause");
before the return 0; is the right way to go. But this only works for windows.
Gross.
That's only if you want the ugly "Press any key to exit . . ." or whatever.
It's so much more awesome to use:
Code
while (!kbhit());

remember to include conio.h (though mine has it in stdio.h also).



None.

May 24 2008, 1:19 pm Brontobyte Post #89



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. :-(



None.

May 24 2008, 1:25 pm MrrLL Post #90



Ctrl + F5



None.

May 24 2008, 1:55 pm Brontobyte Post #91



Quote from WoAHorde
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?

Quote from name:Merrell
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*



None.

May 24 2008, 2:51 pm Money Post #92



Quote from Brontobyte
Quote from WoAHorde
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?

Quote from Brontobyte
Quote from name:Merrell
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.



None.

May 24 2008, 9:23 pm Brontobyte Post #93



Quote from Money
Quote from Brontobyte
Quote from WoAHorde
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?

Quote from Brontobyte
Quote from name:Merrell
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.



None.

May 24 2008, 9:44 pm WoAHorde Post #94



Use a while loop then.



None.

May 24 2008, 9:56 pm Brontobyte Post #95



Quote from WoAHorde
Use a while loop then.

I have no idea how to do this.



None.

May 24 2008, 10:37 pm WoAHorde Post #96



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.



None.

May 24 2008, 10:57 pm Brontobyte Post #97



It didn't work...



None.

May 24 2008, 11:04 pm DT_Battlekruser Post #98



What is with C and using >> and << as syntax :wtfage:

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.



None.

May 24 2008, 11:17 pm Brontobyte Post #99



------ 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..."



None.

May 25 2008, 5:00 am Epsilonite Post #100



Line 20
Code
cout << b * b * b "\n";
should be replaced with this:
Code
cout << 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.

Post has been edited 1 time(s), last time on May 25 2008, 6:03 am by Epsilonite.



None.

Options
Pages: < 1 « 3 4 5 6 7 >
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[03:08 pm]
Oh_Man -- example of wat u mean?
[05:59 am]
NudeRaider -- *is
[05:17 am]
NudeRaider -- despite all its flaws the sound design its fantastic
[10:29 pm]
Oh_Man -- homeworld 3 = massive disappointment
[2024-5-14. : 10:05 am]
Moose -- ya
[2024-5-14. : 5:23 am]
zsnakezz -- yes
[2024-5-12. : 8:51 pm]
l)ark_ssj9kevin -- Are you excited for Homeworld 3?
[2024-5-12. : 8:44 pm]
l)ark_ssj9kevin -- Hi Brusilov
[2024-5-12. : 4:35 pm]
O)FaRTy1billion[MM] -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
my server that was hosting it died
[2024-5-10. : 8:46 pm]
NudeRaider -- Brusilov
Brusilov shouted: Hey, what happened to EUDDB? Is there a mirror for it somewhere? Need to do a little research.
https://armoha.github.io/eud-book/
Please log in to shout.


Members Online: 1alicec5985ec2, 2giannae261gb5