Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 490727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:56:19+00:00 2026-05-13T01:56:19+00:00

I want the function getCategory() to return invalid , instead of printing the word

  • 0

I want the function getCategory() to return “invalid” , instead of printing the word “invalid” (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero).
please help:

#include<stdio.h>
#include<conio.h>
char getCategory(float height,float weight)
{
char invalid = '\0'; 
float bmirange;
if(height<=0 || weight<=0)
return invalid;
else
 {
height=height*0.01;       
bmirange=[weight/(height*height)];
if(bmirange< 15 )
   return starvation;
 }  
}

/* return the following to category
If bmi range < 15 then category is "starvation"
    If bmi range >=15 && bmi range < 18.5 then category is "underweight"
    If bmi range >=18.5 && bmi range < 25 then category is "normal"
    If bmi range >= 25 && bmi range < 30 then category is "overweight"
    If bmi range >=30 && bmi range < 40 then category is "obese"
    If bmi range >=40 then category is "morbidly obese
*/


int main()
 {
 char Category;
 float height,weight;
 printf("enter height");
 scanf("%f",&height);
 printf("enter weight");
 scanf("%f",&weight);
 Category=getCategory(height,weight);
 if(Category == 0)
 printf("invalid");
 else
 printf("%c", Category);
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:56:20+00:00Added an answer on May 13, 2026 at 1:56 am

    Change the return type to a char *, then return a pointer to your various category strings.
    You also need to fill in the checks for the various bmi levels.

    Looks a lot like homework; please mark it as such if so.

    Here’s my solution… but I’ve randomized the order of the lines since you do need to do your own homework. There should be a few hints in this though, such as struct and the return lines.

        scanf("%f",&height);
    struct bmicategory {
    }
            {18.5, "normal"},
        return categories[i-1].name;
        float bmi = weight / (height * height);
        struct bmicategory categories[] = {
        printf("enter weight (in kg): ");
    
        };
        char *name;
    
        return 0;
    
            {40, "morbidly obese"},
            {15, "underweight"},
            }
        scanf("%f",&weight);
        for(i=1; i<sizeof(categories)/sizeof(struct bmicategory); i++) {
    #include<stdio.h>
            if(bmi < categories[i].value) {
                break;
        printf("%s\n", category);
        height = height * 0.01;
        printf("enter height (in cm): ");
            {25, "overweight"},
    
        category=getBmiCategory(height,weight);
    
    int main() {
        float value;
        int i;
        /* printf("BMI = %f\n", bmi); */
    }
    };
        float height;
            {30, "obese"},
        }
        char *category;
    
        char *name = NULL;
            {0, "starvation"},
    char *getBmiCategory(float height, float weight) {
        float weight;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a function to return the product of all the values in a
I want a function that can take a number (say 1000.43) and return the
I want a function/code which will return the value that the user submitted for
I want a function that will return last/first N element of an array. For
I want a function that will take two lists A and B and return
I want following function range((1,1), (2,2)) which return Seq[(Int,Int)]((1,1),(1,2),(2,1),(2,2)) It is analog for one
Want the function to sort the table by HP but if duplicate HPs then
Ideally I want a function something like the following (this example doesn't compile): void
I just want a function that can take 2 parameters: the URL to POST
I only want this function to run if .toolbar li does not have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.