Question

I'm trying to write a program in C that calculates the area of a rectangle. I...

I'm trying to write a program in C that calculates the area of a rectangle. I need to have a function that gets dimensions from a user and stores them with pointers and addresses and another function that calculates the area... my question is how do i access that values from the dimension function so that I can use it in my calculation and main function.. for example.

void userDimensions(float *base, float *height){

scanf("%lf" , base);

scanf("%lf", height);

}

float calcArea(){

float area;

area = base * height;

return area;

}

int main{

printf("The area is %f " , area);

}

i have never programmed in C and i'm having a hard time. Can anyone help me please?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void userDimensions(float *base, float *height) {
    scanf("%f", base);
    scanf("%f", height);
}

float calcArea(float base, float height) {
    float area;
    area = base * height;
    return area;
}

int main() {
    float base, height, area;
    userDimensions(&base, &height);
    area = calcArea(base, height);
    printf("The area is %f ", area);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
I'm trying to write a program in C that calculates the area of a rectangle. I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to change my code so i no longer need the function that reads...

    I am trying to change my code so i no longer need the function that reads in the users base and height input but rather uses the implementation of argument vector in C. I want to accept command line arguments and have it calculate my area. so i want to type this into the command line and have it calculate my area project1 5 4 #include <stdio.h> void userDimensions(float *base, float *height) { scanf("%f", base); scanf("%f", height); } float calcArea(float...

  • I have this C program that calculates an input and converts it to a BMI calculation....

    I have this C program that calculates an input and converts it to a BMI calculation. Any idea how this would look as an LC3 program? I'm taking an LC3 programming class next semester and want an idea of what this code would even translate to, just trying to get a head start. I'm more so curious on how to get user input in a LC3 program, then I can try myself and figure it out from there. int main()...

  • I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the...

    I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...

  • I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle):...

    I'm having trouble getting my program to print shapes For example: Which shape (L-line, T-triangle, R-rectangle): L Enter an integer length between 1 and 25: 13 ************* Which shape (L-line, T-triangle, R-rectangle): t Enter an integer base length between 3 and 25: 5 * ** *** **** ***** Which shape (L-line, T-triangle, R-rectangle): r Enter an integer width and height between 2 and 25: 4 5 **** **** **** **** **** Here's my code: #include <stdio.h> #include <ctype.h> const int...

  • #1 Write a java program which calculates the area of either a Triangle or a Rectangle....

    #1 Write a java program which calculates the area of either a Triangle or a Rectangle. Use Scanner to take an input field to tell you if the area to be calculated is for a Triangle or is for a Rectangle. Depending on that input - the program must call either the Triangle method or the Rectangle method. Each of those methods must receive 2 input fields from the user - one for base and one for height in order...

  • Using the c++ language 1) Create a function that calculates the area of a circle "circeArea...

    Using the c++ language 1) Create a function that calculates the area of a circle "circeArea ()". The function should take a single float parameter radius and return a float area. 2) Create a function to calculate the area of a rectangle. 3) Creat a function to calculate the area of a triangle when given base and height as parameters provided by the user.

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • I'm having with my C program whenever i insert numbers it keeps outputting zeros here's the...

    I'm having with my C program whenever i insert numbers it keeps outputting zeros here's the code: #include<stdio.h> int main(void) {    int weeklyhours;    double hourlyrate;    double grosspay;    double netpay;    double federal;    double state;    double FICA;    double Medicare;    grosspay= weeklyhours * hourlyrate;    federal = grosspay * 0.1;    state = grosspay * 0.06;    FICA = grosspay * 0.062;    Medicare = grosspay * 0.0145;    netpay = grosspay - (federal...

  • C program help: Write a C program that uses three functions to perform the following tasks:...

    C program help: Write a C program that uses three functions to perform the following tasks: – The first function should read the price of an item sold at a grocery store together with the quantity from the user and return all the values to main(). example: #include void getInput(int *pNum1, int *pNum2); // note: *pNum1 & *pNum2 are pointers to ints int main () {    int numDucks,numCats;    getInput(&numDucks, &numCats); // passing addresses of num1 & num2 to...

  • Program Description Write a program that calculates the distance between two places on Earth, based on...

    Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earth’s mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed: Program must have header comments stating the author of the Program, date, and Program Description. Include the math.h header file Initialize a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT