Lets say we want to print Numbers between 4 and 6, including 4 and 6.
#include<iostream>
using namespace std;
int main()
{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+ rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.
cout<<endl<<endl;
return 0;
}
Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.
Simple!
C++: How to detect that user Pressed P button from keyboard? - Yahoo! Answers
#include<iostream>
using namespace std;
int main()
{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+ rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.
cout<<endl<<endl;
return 0;
}
Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.
Simple!
#include<iostream>
using namespace std;
int main()
{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+ rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.
cout<<endl<<endl;
return 0;
}
Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.
Simple!
using namespace std;
int main()
{
int x;
for ( x = 1 ; x <= 70 ; x++ ) // you can replace 70 with Any Number.
cout<< 4+ rand() % 3 <<endl; // to Produce Numbers between 4 & 6 including 4 and 6.
cout<<endl<<endl;
return 0;
}
Mod of 3 with any random number will give value less than 3 and greater than 0, and by adding any number from 0 to 2 with 4, we get either 4,5 or 6.
Simple!