jeudi 31 octobre 2019

beginner: How to convert random generated number into number from 1 to 7

I am still a beginner to the world of programing in c lang and i would like if i get your help!

#include <stdio.h> 
#include <stdlib.h> 
#include <time.h> 

int main()
{
    int week;

    /* Input week number from user */
    printf("Enter week number(1-7): ");
    scanf("%d", &week);

    switch(week)
    {
        case 1: 
            printf("Monday");
            break;
        case 2: 
            printf("Tuesday");
            break;
        case 3: 
            printf("Wednesday");
            break;
        case 4: 
            printf("Thursday");
            break;
        case 5: 
            printf("Friday");
            break;
        case 6: 
            printf("Saturday");
            break;
        case 7: 
            printf("Sunday");
            break;
        default: 
            printf("Invalid input! Please enter week number between 1-7.");
    }

    return 0;
}

Thats the question that i am trying to do:

"Write a C program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday."

the only thing that is missing for me currently is that i want to make the usuer enters a random number then generate random number between 1 and 7




Aucun commentaire:

Enregistrer un commentaire