I want my program to generate 500 random numbers with the range of 10 and 65. How do I do that?
Currently, my program generates between 0 to 74 random numbers. And also, it seems that my highest and lowest value does not read the random generated number but the range of it. This is my code:
#include<iostream>
#include<exception>
#include<stdlib.h>
using namespace std;
int main(){
int year;
int nextLine = 20;
int highestValue = 0;
int lowestValue = 0;
int ages[500];
int range = 65;
cout << "Enter year today: ";
cin >> year;
srand(year);
cout << "The ages are: \n";
for (int i = 0; i < 500; i++){
ages[i] = rand() % 65 + 10;
cout << ages[i] << " ";
if (i + 1 == nextLine){
cout << "\n";
nextLine += 20;
}
}
for (int j = 0; j < 500; j++){
if (ages[j] > highestValue)
highestValue = ages[j];
if (ages[j] < lowestValue)
lowestValue = ages[j];
}
cout << "\nRange(HV-LV): " << highestValue << " - " << lowestValue << " = " << highestValue - lowestValue;
system("pause>0");
return 0;
}
Aucun commentaire:
Enregistrer un commentaire