Few questions about the functions in C. I am doing my HW now and I got some prob
ID: 3664909 • Letter: F
Question
Few questions about the functions in C.
I am doing my HW now and I got some problems.
The HW is:
(1)Newton’s Second Law of Motion: force = mass * acceleration
(2)Volume of a cylinder: volume_cylinder = PI * radius2 * height
They are 7 of them but I just show 2 since i finished 2. When I run it, It give me a error message and i do not know why.
and my code.
#include
#include
#define pi 3.1415926
#include "data.h"
int force(void)
{
double mass = 0.0, acceleration = 0.0, force = 0.0;
mass = get_mass();
acceleration = get_accleration();
force = acceleration * mass;
printf("force: %0.2lf ", force);
return 0;
}
int volume(void)
{
double volume_cylinder = 0.0, radius = 0.0, height = 0.0;
radius = get_radius();
height = get_height();
volume_cylinder = pi * (radius * radius) * height;
printf("The volume cylinder is: %lf", volume_cylinder);
return 0;
}
---------------------------------------------------------------
#include "data.h"
double get_mass(void)
{
double mass = 0.0;
printf("Enter your mass: ");
scanf("%lf", &mass);
return mass;
}
double get_accleration(void)
{
double acceleration = 0.0;
printf("Enter your accleration: ");
scanf("%lf", &acceleration);
return acceleration;
}
double get_radius(void)
{
double radius = 0.0;
printf("Enter your radius: ");
scanf("%lf", &radius);
return radius;
}
double get_height(void)
{
double height = 0.0;
printf("Enter your height: ");
scanf("%lf", &height);
return height;
}
----------------------------------------------------
#include
double get_mass(void);
double get_accleration(void);
double get_radius(void);
double get_height(void);
------------------------------------------
Did I doing right? for every file?
Explanation / Answer
Answer
As per Your Question and Answer you have write program in good manner .But you need to call From main Function and include what you write data.h header file, then properly call the functions it will execute, But also as per your teacher words you have to call functions mass and acceleration in one .c program and calculate Newton’s Force in that program. Same way you can call radius and height in another .c file and find the volume of cylinder in that program. These can be displayed from your main program. That’s it. Otherwise there is no error from your code. Do these things call from main, then its only execute successfully. I Will give you the code how to call and calculate the values and execution process.
/*
* File: NewtMain.c
* Author: HARE KRISHNA
* Created on 2 February, 2016, 2:35 PM
*/
#include <stdio.h>
#include <stdlib.h>
#include"data.h"
int main(int argc, char** argv) {
//here you need to call the functions what you have declared in data.h
// decalre varaibles here
double newtF;
double mass;
double accelaration;
//get the mass
mass = get_mass();
//get the accelaration
accelaration = get_accelration();
//calculating newton Force formula
newtF = mass * accelaration;
//display the force value
printf("%lf",newtF);
//decalre variables here
double volumeCylinder;
double rad;
double height;
//get the radius
rad = get_raidus();
//get the height
height = get_height();
volumeofCylinder = pi*(rad*rad)*height;re
//Calculates volume of cylinder and displays he
printf("%lf",volumeofCylinder);
return (0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.