scanf读取电影信息

#include <stdio.h>
#include <string.h>

int main(){
    int i, numMovies, rating, favRating, leastRating;
    char movieName[40], favorite[40], least[40];

    favRating = 0;
    leastRating = 10;

    do {
        printf("How many movies have you seen this year? ");
        scanf(" %d", &numMovies);

        if (numMovies < 1) {
            printf("No movies! How can you rank them?/n");
            printf("Try again!/n/n");
        }
    } while (numMovies < 1);

    for (i = 1; i <= numMovies; i++)
    {
        printf("/nWhat was the name of the movie? ");
        printf("(1-word titles only!) ");
        scanf(" %s", movieName);

        printf("On a scale of 1 to 10, what would ");
        printf("you rate it? ");
        scanf(" %d", &rating);

        if (rating > favRating){
            strcpy(favorite, movieName);
            favRating = rating;
        }

        if (rating < leastRating){
            strcpy(least, movieName);
            leastRating = rating;
        }
    }

    printf("/nYour Favorite Movie was %s./n", favorite);
    printf("/nYour Least-favorite Movie was %s./n", least);

    return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266516.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论