c - Loop to ask if user wants to play again (y/n) -


here code bmi calculator. add question on end asks if user wants calculate bmi or user wants stop. have question y or n answer.

  • y = calculate bmi
  • n = goodbye

my code far:

#include<stdio.h>; void main() {  float w,h,bmi;  printf("vul uw gewicht in in kilogram.");  scanf("%f",&w);  printf("vul uw hoogte in in meters. (bijvoorbeeld: 1.75)");  scanf("%f",&h);  bmi=w/(h*h);  printf("bmi: %f",bmi);  bmi<18.5?printf(" je bent best wel dun eet een burger :p"):(bmi<25)?printf(" lekker gewicht, blijf zo doorgaan"):(bmi<30)?printf(" ik zou wat minder gaan eten als ik jou was"):printf("oh oh, u bent in gevaar"); } 

try this

#include<stdio.h>; void main() {     char opt='y';     while(1)     {     float w,h,bmi;     printf("vul uw gewicht in in kilogram.\n");     scanf("%f",&w);     printf("vul uw hoogte in in meters. (bijvoorbeeld: 1.75)\n");     scanf("%f",&h);     bmi=w/(h*h);     printf("bmi: %f",bmi);     bmi<18.5?printf(" je bent best wel dun eet een burger :p\n"):(bmi<25)?printf(" lekker gewicht, blijf zo doorgaan\n"):(bmi<30)?printf(" ik zou wat minder gaan eten als ik jou was\n"):printf("oh oh, u bent in gevaar\n");         printf("calculate again : n exit, y continue?\n");         scanf("%c&*c",&opt);         if(opt=='n')         {             printf("exit\n");             break;         }     } } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -