How to make a program repeat 1000 times

I have been trying to make this program repeat 1000 times heres my code please help!

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>


using namespace std;

const int DIE_SIDES = 1;

int main(void)
{


srand( time(0) );

double n1 = (double)rand()/RAND_MAX;
std::cout << "first random value, a double in [0,1] is: "
<< n1 << endl;

double n2 = (double) rand()/RAND_MAX;
std::cout << "second random value, a double in [0,1] is: "
<< n2 << endl;

double n3;
double k;


n3 = 1-(n1 +n2);

if (n1 + n2 > n3)

{
if (k++ <= 0);

// declare a variable
int i;
for(i=1000; i > 1; k++)
cout << k++ << endl;
}

system("pause");

return 0;
}

however all I get is the infinite number 7.00189e+263
1
2
3
for(i=1000; i > 1; k++)
cout << k++ << endl;
}


This will either never loop or loop forever, depending on how your compiler defines an uninitialized variable (for signed ints it is usually the negative max).
Also, you don't ever define k, so you will also have problems with you checks/loops....plz fix the problems.
Why would it loop........ the end condition is effectively the same as the start condition. You give i a value of 1000 and say loop until i is > 1
You need:
for(int i=0;i<1000;i++)
{
//stuff goes here
}
.....and you should place your code between code tags to make it easier to read.
This will either never loop or loop forever, depending on how your compiler defines an uninitialized variable (for signed ints it is usually the negative max).
Why would it loop........ the end condition is effectively the same as the start condition.

You're both wrong. It will loop forever in every compiler.
For this for loop:
1
2
for (<a>;<b>;<c>)
    <d>;
the equivalent while loop is always
1
2
3
4
5
6
7
{
    <a>;
    while (<b>){
        <d>;
        <c>;
    }
}
Last edited on
Whoops, I apparently missed the i=1000...somehow... >.>
Topic archived. No new replies allowed.