[QUOTE=Mega1mpact;23872562]I just want to delete everything in the ram except the stuff that is used by the system itself. So tgat it's in the same state like if you just rebooted it.[/QUOTE]
Try task manager bro.
I was wondering, what is the difference between using a for loop and a while loop.
for (x = 0; x < 10; x++)
VS
while (x < 10) { x++ }
is there an advantage to one or the other or something?
[QUOTE=The DooD;23875051]I was wondering, what is the difference between using a for loop and a while loop.
for (x = 0; x < 10; x++)
VS
while (x < 10) { x++ }
is there an advantage to one or the other or something?[/QUOTE]
For one thing it saves you one infinite loop when you forget to add the x++ the first time you test it :v:
[editline]07:34PM[/editline]
With VS2008 with the XNA plugin thing is there a way to get it to copy a folder from your project directory to the outputted .exe's directory?
[QUOTE=The DooD;23875051]I was wondering, what is the difference between using a for loop and a while loop.
for (x = 0; x < 10; x++)
VS
while (x < 10) { x++ }
is there an advantage to one or the other or something?[/QUOTE]
One makes it obvious what you're trying to do. You're missing a line for your second example, by the way (x = 0).
[QUOTE=The DooD;23875051]I was wondering, what is the difference between using a for loop and a while loop.
for (x = 0; x < 10; x++)
VS
while (x < 10) { x++ }
is there an advantage to one or the other or something?[/QUOTE]
Nope, these two pieces of code do the same:
[cpp]
int i = 0;
while ( i < 10 )
{
std::cout << "LO";
++i;
}
[/cpp]
And
[cpp]
for( int i = 0; i < 10; ++i )
std::cout << "LO";
[/cpp]
[editline]09:43PM[/editline]
Basically for just makes it more clear that you're iterating over something.
Hi i just wondered if anyone on here has used the FlatRedBall engine or anything like it?
As i was thinking of having a go at a kind of 2.5D platformer like duke nukem Manhattan or facewound
[QUOTE=esalaka;23875594]
Basically for just makes it more clear that you're iterating over something.[/QUOTE]
So basically there's no difference for the user, it's purely for the programmers benefit?
[QUOTE=The DooD;23875861]So basically there's no difference for the user, it's purely for the programmers benefit?[/QUOTE]
Well yeah, that's what imperative languages are all about.
[QUOTE=Robert64;23875337]For one thing it saves you one infinite loop when you forget to add the x++ the first time you test it :v:
[/QUOTE]
Haha :wtc: I actually went and put them both together and forgot it :S
I know it's really simple(just starting out(again)), but this baffled me as to why it kept saying the variable was missing a curly bracket even though it's not a function.
[code]#include <iostream>
using namespace std;
int main()
{
int thisisanumber; //It kept saying this needed the curly bracket.
cout<<"Please enter a number: ";
cin>> thisisanumber;
cin.ignore();
cout<<"You entered: "<< thisisanumber <<"\n";
cin.get();
}
[/code]
That's not the real code by the way, but I based it closely off this beginner's tutorial code, so it's pretty close.
Works fine for me:
[code]z33ky@mobileblahbuntu:~/code$ g++ a.cpp
z33ky@mobileblahbuntu:~/code$ ./a.out
Please enter a number: 42
You entered: 42
z33ky@mobileblahbuntu:~/code$ [/code]
a.cpp contains the exact code you posted.
It should work I think, if you would show us the real code we can figure out the real problem.
Oh, and you're not returning a value at the end of the main function
You don't need to. For main, when a return-statement is missing a return 0 is implicit.
[code]#include <iostream> //Ensures you can see and write text.
using namespace std; //Forgot what this is for but you need it, I guess.
int main() //Main function is vital in all programs. It's the first to run.
{
int number,number2; //It kept saying this needed the curly bracket at school but it's fine here. idk
cout << "Please enter a number: "; //The program asks you to write a number.
cin >> number; //This part lets you write the number.
cin.ignore(); //This, apparently, makes sure that hitting enter doesn't affect the input also my stomach is a wolf.
cout << "You entered: "<< number <<"\n"; //This shows what number you entered.
number2=number+number; //This, I think, doubles the number variable. It won't run so I don't know if it works.
cout << "The double of that is "<< number2 <<"\n"; //Shows the result.
cin.get(); //Waits for input.
return 1; //Ends the program.
}
[/code]
I replicated the code as closely as I could remember. The many comments are so I don't forget things.
[cpp]#include <iostream> //Includes the iostream-header, which contains stuff for input and output
using namespace std; //Imports the std-namespace into the current namespace (meaning that you don't have to use the scoping operator; e.g. without it you need std::cout and std::cin, now just cout and cin)
int main() //Main function is vital in all programs. It's the first to run.
{
int number,number2; //It kept saying this needed the curly bracket at school but it's fine here. idk
cout << "Please enter a number: "; //The program asks you to write a number.
cin >> number; //This part lets you write the number.
cin.ignore(); //This discards one character (which will likely be a new-line character from hitting enter)
cout << "You entered: "<< number <<"\n"; //This shows what number you entered.
number2=number+number; //This stores the double of number into number2 (alternative to number2=number*2, which would be more favorable)
cout << "The double of that is "<< number2 <<"\n"; //Shows the result.
cin.get(); //Waits for input.
return 0; //Returns an exit-code (should be 0 if all went fine)
}[/cpp]
Fixed some comments for you ;)
Also, in my opinion you should use more spaces and newlines. It just looks so cluttered. Though that does not matter for now, as you've just began learning :)
[QUOTE=Murkat;23878186][code]#include <iostream> //Ensures you can see and write text.
using namespace std; //Forgot what this is for but you need it, I guess.
int main() //Main function is vital in all programs. It's the first to run.
{
int number,number2; //It kept saying this needed the curly bracket at school but it's fine here. idk
cout << "Please enter a number: "; //The program asks you to write a number.
cin >> number; //This part lets you write the number.
cin.ignore(); //This, apparently, makes sure that hitting enter doesn't affect the input also my stomach is a wolf.
cout << "You entered: "<< number <<"\n"; //This shows what number you entered.
number2=number+number; //This, I think, doubles the number variable. It won't run so I don't know if it works.
cout << "The double of that is "<< number2 <<"\n"; //Shows the result.
cin.get(); //Waits for input.
return 1; //Ends the program.
}
[/code]
I replicated the code as closely as I could remember. The many comments are so I don't forget things.[/QUOTE]
I just copy pasted that and it works fine. Perhaps it's your compiler or something? I had a problem with Code::Blocks because it was automatically saving .cpp files and .c files, maybe it's something similar.
I'm having a problem with simple header files. What's wrong with this set of files?
main.cpp:
[cpp]#include <iostream>
#include "square.h"
int main()
{
for (int i = 0; i <= 100; i++) {
std::cout << square(i, i);
}
return 0;
}[/cpp]
square.h:
[cpp]#ifndef GUARD_square_h
#define GUARD_square_h
int square(const int&, const int&);
#endif[/cpp]
square.cpp:
[cpp]#include "square.h"
int square(const int& int1, const int& int2)
{
return int1 * int2;
}[/cpp]
Thanks, I've only just started bothering with headers.
Nothing wrong as far as I can tell. What's your actual problem?
[QUOTE=nos217;23880950]I'm having a problem with simple header files. What's wrong with this set of files?[/QUOTE]
There seems to be nothing wrong.
Also, it really doesn't make sense to pass int references, you know?
...Whatever. :D
Well my C++ book (Accelerated C++) doesn't actually explain how to correctly compile them, so I've just run "g++ main.cpp". I get the error:
[code]/tmp/ccPdAxOt.o: In function `main':
main.cpp:(.text+0x20): undefined reference to `square(int const&, int const&)'
collect2: ld returned 1 exit status[/code]
[editline]11:52PM[/editline]
[QUOTE=esalaka;23881266]There seems to be nothing wrong.
Also, it really doesn't make sense to pass int references, you know?
...Whatever. :D[/QUOTE]
Yeah I know, I was just fitting in other things I learned in that chapter, not necessarily for a good purpose.
Whats an easy way to parse a multiple level array? So like
{a, {b, c} }
[QUOTE=nos217;23881282]Well my C++ book (Accelerated C++) doesn't actually explain how to correctly compile them, so I've just run "g++ main.cpp". I get the error:
[code]/tmp/ccPdAxOt.o: In function `main':
main.cpp:(.text+0x20): undefined reference to `square(int const&, int const&)'
collect2: ld returned 1 exit status[/code][/QUOTE]
You need to compile both .cpp files (all in one command, not separately).
[code]g++ main.cpp square.cpp[/code]
If you ever get an "undefined reference" error, it probably means you haven't compiled something you need to. The linker (which runs after the compiler) links the compiled units together, and it gives you that error if it can't find a unit it needs. (There are also other reasons you'd get that error, but you don't need to worry about them yet.)
Ohhh yeah I get it. Thanks a lot!
[QUOTE=shill le 2nd;23881845]You need to compile both .cpp files (all in one command, not separately).
[code]g++ main.cpp square.cpp[/code]
[/QUOTE]
Alternately, you can do
[code]g++ -c main.cpp
g++ -c square.cpp[/code]
which will produce main.o and square.o respectively, then
[code]g++ main.o square.o[/code]
which will link the two object files to produce an executable.
For a small project it's simpler to just compile everything with one command as shill said. The benefit of compiling separately is that when you change something, you only have to recompile the files that are affected by the change, which can save a lot of time in a large project.
Ah right, I get it. So basically if I have a huge project, and I just want to change one little value, I don't need to recompile the entire thing. Handy.
Indeed. Pretty much every IDE does that for you too.
Me again with another nooby question.
What is the point in constant values? VS just not changing a variable value.
[QUOTE=The DooD;23897082]Me again with another nooby question.
What is the point in constant values? VS just not changing a variable value.[/QUOTE]
Constants can be optimized away.
[QUOTE=The DooD;23897082]Me again with another nooby question.
What is the point in constant values? VS just not changing a variable value.[/QUOTE]
It depends what you mean by constant value. What programming language? Which situations are you referring to?
Noob c++ question. If I use printf, and I do something like
printf("Error type: %s", get_errortype())
it will replace %s with the thing output by the function. But what do I do if I need to do it with cout?
Sorry, you need to Log In to post a reply to this thread.