'How do I add numbers into an array from a loop that creates random numbers in C++?
How do I add numbers into an array from a loop that creates random numbers? I also need to sort these numbers in a certain way. The next number cannot be greater than the previous one. Can someone help me with this? Here is a copy of some of the code I made.
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <vector>
using namespace std;
int main() {
srand((unsigned) time(0));
int randomNumber;
int counter = 1;
int emptyArray[5] = {0};
while (counter <= 5){
randomNumber = (rand() % 30) + 40;
cout << " ------------ ";
cout << '\n';
cout << '\n';
cout << randomNumber << '\n';
cout << '\n';
cout << '\n';
cout << counter << " number of times" << '\n';
cout << " --------- ";
counter++;
cout << emptyArray[randomNumber] << " ";
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|