- snip -
[editline]25th April 2013[/editline]
-snip- Fixed it. I'm fucking stupid sometimes.
[quote]
Write a program that ccontinues to asks the user to enter any number other than 5 until the user enters the number 5.
Then tell the user "Hey! you weren't supposed to enter 5!" and exit the program.
★ Modify the program so that after 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient then I am, you win." and exit.
[/quote]
I'm on the second part, I have a for loop to do 10 iterations but I can't figure out how to jump out of the loop if the user enters a 5 before the 10th iteration. I assume you have to use nested loops, but I've tried a for loop inside a while, a while inside for loop, for loop inside do while, I can't figure it out..
Anyone know any quality online classes for languages like C++ and Python? I'm content on learning those because many great engines are created USING those languages!
[QUOTE=NPC;40426162]Anyone know any quality online classes for languages like C++ and Python? I'm content on learning those because many great engines are created USING those languages![/QUOTE]
I'm learning C++ right now through these tutorials. [url]http://www.youtube.com/course?list=ECAE85DE8440AA6B83[/url]
[QUOTE=wlitsots;40425949]I'm on the second part, I have a for loop to do 10 iterations but I can't figure out how to jump out of the loop if the user enters a 5 before the 10th iteration. I assume you have to use nested loops, but I've tried a for loop inside a while, a while inside for loop, for loop inside do while, I can't figure it out..[/QUOTE]
are you using c++? use break
[QUOTE=wlitsots;40426206]I'm learning C++ right now through these tutorials. [url]http://www.youtube.com/course?list=ECAE85DE8440AA6B83[/url][/QUOTE]
Wow man, thanks. <3 8D
[QUOTE=NPC;40426455]Wow man, thanks. <3 8D[/QUOTE]
[url]http://www.learncpp.com/[/url] is pretty good too.
Trying to get back into the flow of OpenGL. Can someone explain to me what the value of 0 in this snippet is?
[cpp]glBindFragDataLocation( shaderProgram, 0, "outColor" );[/cpp]
From what I understand you use different numbers as the second variable for different outputs, but how does this work? Is overv still around, because these tuts of his are great.
[QUOTE=a-k-t-w;40426406]are you using c++? use break[/QUOTE]
[code]
int main() {
int a;
for (int x = 1; x <= 10; x++) {
cout << "Enter a number other than 5: ";
cin >> a;
if (a == 5) {
break;
}
}
if (a == 5) {
cout << "You weren't supposed to enter 5!";
} else {
cout << "You win!";
}
}
[/code]
I got it, thanks!
It was so simple but took me forever to figure out.
[editline]25th April 2013[/editline]
Is there a way to use variables declared in one function, in another function?
No, you'd have to pass the variables to the other function, or declare the variables globally (outside the function, in a common file)
[QUOTE=Ehmmett;40428561][code]test = {}
var = table.insert(test,1)
print(var,test[1])
test[1] = 1337
print(var,test[1])[/code]
What can I do to achieve something where var would point to the actual table instead of nil? table.insert returns nil for some reason.[/QUOTE]
why do you need table.insert to return the table when you're passing the table to table.insert in the first place?
[code]test = {}
var = test
table.insert(test, 1)[/code]
Not what you want?
[code]local light = {}
function light.new(description)
local new_light = {
pos = { 0, 0, 0 }
-- ...
}
-- maybe do some stuff to new_light here too
return new_light
end[/code]
Mysql
How do I do a CHECK constraint that ensures the value inputed is between 0 and 5000?
Can someone explain to me what defining a function with the same name as class, inside of that class? Another thing, if I have an Entity class and I want to make an entity by deriving from the Entity class how would I get that one in specific so I can call it's own functions?
[code]class foo{
foo(){
printf("I'm a function!");
}
}
[/code]
Most languages let you override the constructor. The constructor always returns an object of your class (in this case "foo")
[QUOTE=SammySung;40429347]Mysql
How do I do a CHECK constraint that ensures the value inputed is between 0 and 5000?[/QUOTE]
Mysql ignores check constraints, so you'll probably want to check your value before input.
[editline]26th April 2013[/editline]
[QUOTE=jrj996;40430775]Can someone explain to me what defining a function with the same name as class, inside of that class? Another thing, if I have an Entity class and I want to make an entity by deriving from the Entity class how would I get that one in specific so I can call it's own functions?[/QUOTE]
Objects of classes are created using the constructor, when you use the 'new' syntax you're actually calling the constructor. The constructor of the super class (in Java all Classes extend from the Object class by default, I'm pretty sure this is the same for other languages) is used when you haven't overridden the constructor (create your own constructor method by creating a method with the same name as the class). When you create your own constructor you can define which methods are called at object creation and which parameters should be given and set for the object.
For example, if you're using a class Box and Box has a color, you'll probably want to define the color at object creation, you do this by overriding the constructor.
[cpp]
public class Box {
private Color color;
public Box(Color color) {
this.color = color;
}
}
[/cpp]
[QUOTE=wlitsots;40426206]I'm learning C++ right now through these tutorials. [url]http://www.youtube.com/course?list=ECAE85DE8440AA6B83[/url][/QUOTE]
Switch to something else immediately. Thenewboston is terrible and shouldn't be recommended to anyone.
-snip- Holy shit I got it.. had to use 'new'.
Thanks CmdrMatthew :)
[QUOTE=sambooo;40436933]Switch to something else immediately. Thenewboston is terrible and shouldn't be recommended to anyone.[/QUOTE]
Eugh the comments
[quote]For a faster, better alternative instead of <<endl; use \n* In your code it would look like this
cout<<"Hello Bitches\n";[/quote]
it's not like endl's designed to do more than a newline character!! no flushing buffers or anything
Mysql!
How can I make it only show entries where Total Sales is between 2 and 10?
Query:
[quote]SELECT P.PRODID, P.PRODNAME, SUM(O.QTYSOLD) AS "TOTAL SALES"
FROM PRODUCT P
INNER JOIN ORDERLINE O
ON P.PRODID = O.PRODID
GROUP BY P.PRODID, P.PRODNAME
ORDER BY "TOTAL SALES", P.PRODID[/quote]
Output:
[img]http://puu.sh/2HYo5.png[/img]
Got it, yo.
[quote]SELECT P.PRODID, P.PRODNAME, SUM(O.QTYSOLD) AS "TOTAL SALES"
FROM PRODUCT P
INNER JOIN ORDERLINE O
ON P.PRODID = O.PRODID
HAVING SUM(O.QTYSOLD) BETWEEN 2 AND 10
GROUP BY P.PRODID, P.PRODNAME
ORDER BY "TOTAL SALES", P.PRODID[/quote]
You have no where clause. You should be able to do something like "SELECT foo FROM bar WHERE foo > 2"
[QUOTE=Protocol7;40440576]You have no where clause. You should be able to do something like "SELECT foo FROM bar WHERE foo > 2"[/QUOTE]
I needed to use HAVING, not WHERE
Can someone explain to me binary (search) trees in java or at least link me a good tutorial.
We are supposed to read a file where one of the lines looks like this: 110;laptop;HP;Probook;24;675.90;Intel I3 2.1Ghz;4;13.3
and then store them in a binary tree where the search is based on the first number(110 in this case)
Im to stupid to add external API to Java in eclispe i want test the facepunch api :/
How can i use the facepunch api in Java?!
You mean the one at facepun.ch? You have to send an HTTP request, and handle the result as JSON.
[cpp]
glGetError();
GLfloat verts[] = {
0.0f, 1.0f, 0.0f, 1.0f,
-1.0f, 0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f };
GLfloat colors[] = {
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f };
GLuint vert_array = 0;
GLuint color_buffer = 0;
glGenVertexArrays(1, &vert_array);
glBindVertexArray(vert_array);
[/cpp]
I keep getting a segfault on glGenVertexArrays(), anyone know what could be causing it ?
Nevermind it was being caused by glew.
[QUOTE=RandomDexter;40442002]Can someone explain to me binary (search) trees in java or at least link me a good tutorial.
We are supposed to read a file where one of the lines looks like this: 110;laptop;HP;Probook;24;675.90;Intel I3 2.1Ghz;4;13.3
and then store them in a binary tree where the search is based on the first number(110 in this case)[/QUOTE]
A binary search tree is a binary tree, that is a tree where each node has at most two children.
All nodes in one child-branch have smaller values than the parent-node and all nodes in the other child-branch have bigger values. I've usually seen it implemented such that the first-branch contains the smaller ones and the second the bigger ones.
So to build a binary search tree, if you have an empty tree, the first node becomes the root.
Otherwise, if the number is smaller, you select the smaller branch and check again or if it is bigger, then you select the bigger branch and check again.
There usually cannot be two nodes with the same value in a binary search tree.
Lookups are pretty much the same. You compare the values and if it is {smaller, bigger}, continue with the {smaller,bigger} branch, if the values are the same, the lookup succeeded, if there is no further branch, the lookup failed (the tree does not contain the value).
Ludum Dare progress. Developing in LÖVE. Minimalism kinda sucks as a theme.
[img]http://i.imgur.com/J78Cy1C.png[/img]
[QUOTE=Clavus;40445938]Ludum Dare progress. Developing in LÖVE. Minimalism kinda sucks as a theme.
[img]http://i.imgur.com/J78Cy1C.png[/img][/QUOTE]
I just use it as an excuse to not make any art and stick with solid colors
Well I'm back again, this time I'm not seeing anything on the screen even though everything looks ok and there are no obvious errors.
[cpp]
void Engine::mainLoop()
{
ShaderProgram* s = new ShaderProgram();
s->createShaderProgram("TestProgram");
s->addShader("shaders/vertex.glsl", "base-vert", GL_VERTEX_SHADER);
s->addShader("shaders/fragment.glsl", "base-frag", GL_FRAGMENT_SHADER);
s->attach_shader("base-vert");
s->attach_shader("base-frag");
s->loadProgram();
s->bind_attrib(0, "position");
s->bind_attrib(1, "color");
GLfloat verts[] = {
0.0f, 1.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f };
GLfloat colors[] = {
1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 1.0f, 1.0f };
GLuint vert_buffer = 0;
GLuint color_buffer = 0;
GLuint vao = 0;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glGenBuffers(1, &vert_buffer);
glBindBuffer(GL_ARRAY_BUFFER, vert_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
glGenBuffers(1, &color_buffer);
glBindBuffer(GL_ARRAY_BUFFER, color_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
GLuint position = glGetAttribLocation(s->getProgramGLID(),"position");
GLuint color = glGetAttribLocation(s->getProgramGLID(),"color");
glEnableVertexAttribArray(position);
glEnableVertexAttribArray(color);
glVertexAttribPointer(position, 4, GL_FLOAT, GL_FALSE, 0, 0);
glVertexAttribPointer(color, 4, GL_FLOAT, GL_FALSE, 0, 0);
s->use_program();
while( glfwGetWindowParam(GLFW_OPENED) && !glfwGetKey(GLFW_KEY_ESC) )
{
glClearColor(1.0f, 1.0f, 1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers();
}
}[/cpp]
Nevermind fixed my own shit again, turns out glGetAttribLocation returns GLint not GLuint and the bind name has to match what is in my vertex shader.
Sorry, you need to Log In to post a reply to this thread.