2021年5月5日星期三

I am trying to create time converter using switch statement in c language, but its not working

#include <stdio.h>   #include <conio.h>     int main() {    char question_unit, answer_unit;    int month, days, time_value, time;    float answer;    printf("enter the given time value : ");    scanf("%d", &time_value);    printf("Months  -->a \n");    printf("Days    -->b \n");    printf("Hours   -->c \n");    printf("Minute  -->d \n");    printf("Seconds -->e \n");    printf("enter the given time unit (as per above notation): ");    scanf("%c", &question_unit);    printf("enter the required time unit (as per above notation): ");    scanf("%c", &answer_unit);    switch (question_unit) {      case 'a':        time = 30 * 24 * 60 * 60 * time_value;        break;      case 'b':        time = 24 * 60 * 60 * time_value;        break;      case 'c':        time = 60 * 60 * time_value;        break;      case 'd':        time = 60 * time_value;        break;      case 'e':        time = time_value;        break;      default:        printf("You enter wrong given unit\n");        break;    }    switch (answer_unit) {      case 'a':        answer = time / (30 * 24 * 60 * 60);        break;      case 'b':        answer = time / (24 * 60 * 60);        break;      case 'c':        answer = time / (60 * 60);        break;      case 'd':        answer = time / 60;        break;      case 'e':        answer = time;        break;      default:        printf("You enter wrong asked unit\n");        break;    }    printf("%d --convered--> %f", time_value, answer);    getch();    return 1;  }  

When I am running this code. The scanf() does not work properly. It does not take any value.

https://stackoverflow.com/questions/67409096/i-am-trying-to-create-time-converter-using-switch-statement-in-c-language-but-i May 06, 2021 at 05:43AM

没有评论:

发表评论