-
Help please
Someone please tell me what is wrong with this. I have been working on this for 13 hours and I am at wits end.
Code:
// Name: John King
// Date: Monday February 15 at 8:oo AM
// Desc: The purpose of this project is to modularize our Project One. Also to add
// conversions in for Kelvin and inches.
#include <stdio.h>
//Prototypes
void getInput(int* pFahrenheit, int* pFeet, int* pPounds);
int calc(int* pCelsius, int* pKelvin, int* pMeters, int* pInches, int* pKilograms);
float calcTemp(int fahrenheit, int* pCelsius, int* pKelvin);
float calcDistance(int feet, int* pMeters, int* pInches);
float calcWeight(int pounds);
void display (int fahrenheit, int celsius, int kelvin, int feet, int
meters, int inches, int pounds, int kilograms);
//calls all the other functions
int main(void)
{
int fahrenheit, feet, pounds;
int celsius, kelvin, meters, inches, kilograms;
getInput(&fahrenheit, &feet, £s);
calc(&celsius, &kelvin, &meters, &inches, &kilograms);
display(fahrenheit, celsius, kelvin, feet, meters, inches, pounds, kilograms);
return 0;
}
void getInput(int* pFahrenheit, int* pFeet, int* pPounds)
{
printf("\nName: John King\n");
printf("\nPlease enter an integer value for Fahrenheit:");
scanf("%d", pFahrenheit);
printf("\nPlease enter an integer value for Feet:");
scanf("%d", pFeet);
printf("\nPlease enter an integer value for Pounds:");
scanf("%d", pPounds);
}
int calc(int* pCelcius, int* pKelvin, int* pMeters, int* pInches, int* pKilograms)
{
int fahrenheit, feet, pounds;
int celsius, kelvin, meters, inches, kilograms;
calcTemp(fahrenheit, &celsius, &kelvin );
calcDistance(feet, &meters, &inches);
calcWeight(pounds);
}
float calcTemp(int fahrenheit, int* pCelsius, int* pKelvin)
{
*pCelsius = (fahrenheit - 32) / 1.8;
*pKelvin = *pCelsius + 273.15;
return *pCelsius, *pKelvin;
}
float calcDistance(int feet, int* pMeters, int* pInches)
{
*pMeters = feet / 3.2808399;
*pInches= feet * 12;
return *pMeters, *pInches ;
}
float calcWeight(int pounds)
{
int* pKilograms;
*pKilograms = pounds / 2.20462262;
return *pKilograms ;
}
void display(int fahrenheit, int celsius, int kelvin, int feet, int meters, int
inches, int pounds, int kilograms)
{
printf("\n%15s%15s%15s%15s%15s%15s", "Original", "Value", "Converted To",
"Value", "Converted To", "Value");
printf("\n%15s%15s%15s%15s%15s%15s", "--------", "-----", "------------", "-----",
"------------", "-----");
printf("\n%15s%15d%15s%15.3d%15s%15.3d", "Fahrenheit", fahrenheit, "Celsius", celsius,
"Kelvin", kelvin);
printf("\n%15s%15d%15s%15.3d%15s%15.3d", "Feet", feet, "Meters", meters, "Inches",
inches);
printf("\n%15s%15d%15s%15.3d", "Pounds", pounds, "Kilograms", kilograms);
printf("\n\n");
}
-
-
the output values do not come out right. like the data isn't passing between the functions correctly.
-
#1 - you aren't returning anything in calc (you have an int return type)
#2 - you are getting a seg fault
for #2, you need to trace down the seg fault. I usually start commenting out pieces of the program, preferably starting at the bottom like so:
Code:
someFunction()
{
getSum();
//getDifference();
//getHeight();
//getWeight();
}
....run it, if there's no seg fault, remove a section of comments
Code:
someFunction()
{
getSum();
getDifference();
//getHeight();
//getWeight();
}
oh! there's a seg-fault, it must be in getDifference (the seg fault may be in more than 1 function)
#3 - you can only return 1 "thing" at a time.
-
its not telling me there is a seg fault?
-
Some compilers will not tell you there is a segmentation fault, some will.
Also: When you call calcWeight, you are returning a number, what do you want calcWeight to become?
Code:
int calc(int* pCelcius, int* pKelvin, int* pMeters, int* pInches, int* pKilograms)
{
int fahrenheit, feet, pounds;
int celsius, kelvin, meters, inches, kilograms;
calcTemp(fahrenheit, &celsius, &kelvin );
calcDistance(feet, &meters, &inches);
calcWeight(pounds); //<----- is going to become a number, what do you want to do with this number?
}
basically, if calcWeight(pounds) returns 5.334343, you're typing 5.334343; You want to say somerandomnumber = calcWeight(pounds);
and to top it off, you don't want to store 3.21353 in an int, it's not going to be pretty, put it in a double or something ;)
-
I need all of the calc functions to convert the input values to the appropriate output. My professor said the prototype for calcWeight HAD to matchthat so idk. and also idk how to fix a seg fault. sorry i have only been doing this for like four weeks
-
in the debugger for codeblocks your program fails with segfault at line 86, on the line that does the calculation in calcweight function.
you have piles of pointers flying all over the place, i am not sure they are needed, it seems you think that a functions argument has to be a pointer or something?
-
no i honestly just don't know how to use pointers:( my teacher is very inadequate, and doesn't explain things well. I just need all the values to flow through the program properly so i will get the right output
-
I sent you a pm asking you the project description, it would be helpful if we could know what the requirements are so we don't screw up your grade :)
The biggest thing that would help is how the prototypes are supposed to be set up.
-
alright i shot it to you in an email.
-
-