So I'm writing this console application in
Dev-C++ to script a POV-Ray file that generates a bunch of random spheres, right
This is the source code (spoilered for long maybe):
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <time.h>
using namespace std;
int main(int argc, char *argv[])
{
fstream file_op("random.pov",ios::out);
int x;
int y;
int z;
int i = 0;
int rad = 10;
float r;
float g;
float b;
srand(time(NULL));
file_op << "camera{location <0,50,-100> look_at <0,0,0> }" << endl;
file_op << "background{ color blue 1 green .5 red .5 }" << endl;
file_op << "light_source{<30,50,-30> color red 1 green 1 blue 1}" << endl;
file_op << "light_source{<-30,50,30> color red 1 green 1 blue 1}" << endl;
cout << "camera{location <0,50,-100> look_at <0,0,0> }" << endl;
cout << "background{ color blue 1 green .5 red .5 }" << endl;
cout << "light_source{<30,50,-30> color red 1 green 1 blue 1}" << endl;
cout << "light_source{<-30,50,30> color red 1 green 1 blue 1}" << endl;
for(i = 0; i > 100; i++)
{
x = (rand() & 100 - 1) - 50;
y = (rand() & 100 - 1) - 50;
z = (rand() & 100 - 1) - 50;
r = rand()/(float(RAND_MAX)+1);
g = rand()/(float(RAND_MAX)+1);
b = rand()/(float(RAND_MAX)+1);
file_op << "sphere { <" << x << ", " << y << ", " << z << " >, "
<< rad << " texture{ pigment {color rgbf<"
<< r << ", " << g << ", " << b << ", 0.6>}"
<< "finish {phong 1}}}" << endl;
cout << "sphere { <" << x << ", " << y << ", " << z << " >, "
<< rad << " texture{ pigment {color rgbf<"
<< r << ", " << g << ", " << b << ", 0.6>}"
<< "finish {phong 1}}}" << endl;
}
file_op.close();
system("PAUSE");
return EXIT_SUCCESS;
}
cout is basically there just to put visual confirmation of what I'm writing to the file, on the screen
Problem is, it's ignoring the FOR loop entirely. Nothing being written to the screen, and nothing being written to the file after the initial camera, background, and lightsource commands
Any ideas why the loop seems to be totally ignored?
Posts
Not quite related, but Dev-C++ is outdated. A newer IDE is Code::Blocks, or alternatively you can use Visual Studio Express Edition.
Switch the greater-than sign to a less-than sign. The middle component of a for loop is the condition that must be true for the loop to iterate. Since you set i = 0 to begin with, and then see if i > 100, the loop will never iterate since i is never greater than 100.
E:F,B
Thanks for the help, the program works as intended now
Wii: 5024 6786 2934 2806 | Steam/XBL: Arcibi | FFXI: Arcibi / Bahamut