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 9256383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:55:38+00:00 2026-06-18T11:55:38+00:00

I have to separate a program I created into 1 main function and 3

  • 0

I have to separate a program I created into 1 main function and 3 user defined functions.
The instructions for my work is as follows:

// gets an integer from the user and returns it // make 3 calls to
this function: // get the length of the rectangle from the user and
return it to main // get the width of the rectangle from the user and
return it to main // get the radius of the circle from the user and
return it to main int GetNum(void);

// takes two arguments, the length and width of the rectangle and
returns the area int CalculateAreaR(int length, int width);

// takes one argument, the radius of the circle and returns the area
double CalculateAreaC(int radius);

I am pretty stuck though. I’ve written the functions but can’t correctly call them to the main function. I know it may be simple but there is just something im not seeing right. the code I have written is as follows:

#include <stdio.h>
#include <math.h>
#define PI 3.14

int GetNum(void)
{
    int length;
    int width;
    int radius;

    printf( " Please enter the length of a rectangle  \n");
    scanf(" %d", &length);
    printf(" Please enter the width of a rectangle \n");
    scanf(" %d", &width);
    printf(" Please enter the radius of a circle \n");
    scanf(" %d", &radius);

    return length, width, radius;
}

int CalculateAreaR(int length, int width)
{   
    return length*width;
}

double CalculateAreaC(int radius)
{
    return PI*radius*radius;
}

int main(void)
{   
    int length;
    int width;
    int radius;
    int areaR;
    double areaC;

    GetNum();


    printf("\nThe area of the rectangle is %d\n", CalculateAreaR);

    printf("\nThe length is %d, the width is, %d and thus the area of the rectangle is %d\n\n", length, width, areaR);

    areaC = CalculateAreaC();

    printf("\nThe area of the circle is %.3f\n", CalculateAreaC);

    printf("\n\n The radius of the circle is %d and the area of the circle is %.3f\n\n", radius, areaC);

    return 0;
}

Can anyone please help me? I’d be very thankful. Im trying my best to learn.

  • 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-06-18T11:55:39+00:00Added an answer on June 18, 2026 at 11:55 am

    In C, a function can only return a single value via the return statement.

    For a simple program, you could make your GetNum() function modify global variables.

    // variables placed outside any function have global scope
    int length;
    int width;
    int radius;
    
    int GetNum(void)
    {
    
        printf( " Please enter the length of a rectangle  \n");
        scanf(" %d", &length);
        printf(" Please enter the width of a rectangle \n");
        scanf(" %d", &width);
        printf(" Please enter the radius of a circle \n");
        scanf(" %d", &radius);
    
        return 0;
    }
    

    This shows declaring the variables at global scope, then using them in the function.

    A more advanced, but usually better, way to return multiple values is for the caller to pass a pointer to a variable, and the function to use the pointer to set the variable. @bash0r showed this technique in his/her answer.

    Now, to call a function, you must always put parentheses after the function name. Always always always. If you put the name without the parentheses, you are not calling the function; you are just referring to the function (you are referencing the address of the function). You have a couple of places where you wanted to call functions but you didn’t put the parentheses.

    Some functions take arguments. When you call a function that takes arguments, you need to pass the arguments in. Here is an example of a function that multiplies a number by a factor and then adds a term.

    float adjust_num(float x, float factor, float term)
    {
        return x * factor + term;
    }
    
    // example of calling the above:
    
    float adjusted;
    
    adjusted = adjust_num(input_value, scale_factor, 0.0f);
    

    In the example, we pass in input_value and scale_factor. We don’t have a constant or variable with a term to add, so we just pass in a literal 0.0 value. So for this example, we are passing all the required arguments. Then the function returns a value, and we collect that output value in the variable adjusted.

    If you do try the global variables as I suggested, you will need to delete the lines that declare the variables inside the main() function. Otherwise you will declare two sets of variables, the ones private inside of main() and the other, global ones. The ones in main() will sort of hide the global ones; we call that “shadowing”, as in “the local variables inside of main() are shadowing the global variables.”

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that starts constantly juggles between 3 separate timers. The main
I am trying to separate a few things in here. I have a program
I have a database containing user details. I don't have separate columns for 'firstname'
I have created an awk program to go through the columns of a file
I have a program that logs into a server and issues commands. The results
I have two separate tables already created and filled with info. The first table
I have a python program that opens several urls in seperate tabs in a
I am developing two java programs that run in separate VM's that have a
Do I need to have separate/multiple workers to run multiple websites (each with a
What's the best way to have separate CSS for IE and other browsers? I'm

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.