PRETTY DIFF This diff is colored to make it clear what parts of the output are wrong. Green indicates things in the correct output that you are missing, red indicates things in your output that shouldn't be there. The - character refers to newlines, so the green e character refers a newline you are missing in your output and the red refers to a newline you need to remove from your output. 1 randArray[e ]- 65d 2 randArray[1 ]- 57d 3 randArray[2 ]- 39d 4 randArray[3 ]- 47d randArray[4 ]- 79d 6 randArray[5 ]- 59d 7 randArray[6 ]- 45d 8 randArray[7 ]- 11d 9 randArray[8 ]- 53d 10 randArray[9 ]- 27d 11 randArray[10 - 14 randArray[11 - 654 13 randArray[12 ]- 79d 14 randArray[13 15 randArray[14 - 82d randArray[15 - 784 12 764 16
Getting an error with my code. Below I have included a screenshot
Instruction:
- In main() for now: do these - one at a time, each in it's own loop (we will make functions out of them later
–Declare an array RandArray with 20 integers
–Assign each of the 20 values with a random value from 0 to 99
- Hint: Use rand()%100
- For mimir: Do not call srand at the top of main.
// normally: Call srand(time(0)) at the top of main
–(you need #include<cstdlib>)
–Write another loop that prints the array, with index values
Important:
If the output values do not match mimir, please add
srand(17); // inside your main function - at the top
My code:
#include <iostream>
using namespace std;
#include <cstdlib>
int main()
{
srand(17);
const int ARRAYSIZE = 20; // size for the array
int RandArray[ARRAYSIZE]; // array declared
int i; // to iterate the loop
// this loop will store the
// random numbers in the array
for (i = 0; i < ARRAYSIZE; i++)
RandArray[i] = rand() % 100;
// this loop will print the array
for (i = 0; i < ARRAYSIZE; i++)
cout << i << " = " << RandArray[i] << endl;
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images