0
// Helps a user decide which homework to do first
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
    // Prompt the user for the number of courses that they have homework in
    int n = get_int("How many courses do you have homework in? ");

    // TODO: Declare an array of courses with the correct number of elements

    // TODO: Prompt the user for their course names and store it in the array
    int courses[n];
    for (int i = 0; i < n; i++)
    {
        courses[i] = get_int("Course: ");
    }
    // Initialize random number generator
    // (found info on https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm)
    time_t t;
    srand((unsigned) time(&t));

    // Find a random number
    int r = rand() % n;

    // TODO: Print out a random course number with index r
}

Can someone help with the todos?

4
  • 1
    Seems like everything is done except for a final print statement.
    – Cliff B
    Nov 4, 2022 at 21:00
  • Which exercise/lab/problem is this in the courseware? Nov 5, 2022 at 10:49
  • This is the high school course adapted from Harvard's CS50 course, so many of the problem sets are similar, if not the same, however, this assignment I rhink is made by my teacher and not included in the courseware. However, I need help on the final print statement please.
    – Tyler
    Nov 6, 2022 at 16:45
  • You've done all the heavy lifting already. r will contain an integer between 0 and (n-1) Now you can use that variable as an index to select (and print) an element in the courses array. You are literary one code line away from completing this task
    – DmitryK
    Nov 20, 2022 at 4:24

0

You must log in to answer this question.

Browse other questions tagged .