First time programming, and I would like some feedback.

This is the code, and I don't know if I was supposed to paste it in C or C++ on Ideone, because my teacher talks about the class like it's just called C programming but we use Visual C++ and Visual Studio 2008/2010 and stuff.

https://ideone.com/clone/c7rHO


Am I even close to doing this right? I barely have a few hours a week to use my laptop, and when I do I don't have a lot of time to learn and code, and this is my first time ever taking a programming class.

If you can, please tell me what I need to fix to satisfy the requirements posted at the beginning of the code.
The code there looks like C. Anything you write in C will usually work with a C++ compiler anyway.

Edit: Could you please post your code on this site in [ code]code tags[/code]
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Problem A:  Write a C program to prompt and input from the user a height in feet and inches.   
Calculate and print the equivalent height in inches, centimeters and meters, 
(printed to the nearest 1000th) but you MUST do the following.

Use a separate function for each conversion that calculates 
and returns (through a return statement) the following measurements:
"	one function converting from feet and inches (parameters) 
to inches (return value)-- there are 12 inches per foot
"	one function from inches (parameter) to centimeters (return value)-- 
there are 2.54 centimeters per inch
"	one function from inches (parameter) to meters (return value)-- 
there are 100 centimeters per meter  
Call that function in main.  Use the following equivalences, 
but figure out the equations based on these (these are NOT the calculations):

Use a function (call from main) to print the input feet & inches and equivalent inches, 
centimeters and meters (with labels -- see test runs).
Use the following input to turn in:  6  2  (for feet & inches), 
in another run: 4  11 (for feet & inches), in another run: 5  6 (for feet & inches).
*/

#include <stdio.h>
#include <stdlib.h>

float getInchesFeet      (float inches, float feet);
float feetToInch     (float feet, float inches);
float inchToCMeter   (float inches, float cmeters);
float inchToMeter    (float inches, float meters);

int main (void)
{
	// local definitions


	// statements
getInchesFeet (float inches, float feet);
printf("%d feet and %d inch(es) is equal to:\n", feet, inches);

getTotalInches   (float feetToInches, float totalInches);
inchToCMeter   (float inches, float cmeters);
inchToMeter   (float inches, float meters);
printf("%6.3f inches\n", toalInches);
printf("%6.3f centimeters\n", cmeters);
printf("%6.3f meters\n", meters);



	system("pause");
	return 0;
}
/* ======= getInchesFeet =========
Asks user to input inches
*/
getInchesFeet (float feet, float inches);

printf("Welcome, please input the feet and and inches in "n n" format: ");
scanf("%d %d", &feet, &inches);


return (feet, inches);

/* ======= feetToInch ========
	Converts feet to inches
	Pre
	Post
*/
float getTotalInches   (float feetToInches, float totalInches)
{
// Local declarations
	float feetToInches;
	float totalInches;
	
	getInchesFeet (float feet, float inches);
	
	feetToInches = feet * 12;
	totalInches = inches + feetToInches;

	return totalInches;
} // feetToInch

float inchToCMeter   (float inches, float cmeters)
{
// Local declarations
	float inches;
	float cmeters;
	
	getTotalInches   (float feetToInches, float totalInches)
	
		cmeters = totalInches * 2.54;
	
	return cmeters;
} // inchToCMeter


float inchToMeter   (float inches, float meters)
{
// Local declarations
	float inches;
	float meters;
	
	getTotalInches   (float feetToInches, float totalInches)
	
		meters = totalInches * 0.0254;
	
	return meters;
} // inchToMeter 
I know it looks weird, but I made everything float because she said she wants everything rounded to the nearest thousandth, so I figured I'd make it float to be on the safe side. Really though I have no idea how to go about this.

My teacher already moved on to harder things and never even went over functions more than once with us. She didn't even do any hands on coding, she just put it on power point and showed a few tid bits of code and said "This is what a function looks like, another set of code that looks like int main with the { } brackets, have fun."
In main none of the variables your using are declared and your function calls are formatted like declarations, ie: getInchesFeet (float inches, float feet);
the type name shouldn't be in function call.
also in that function you return (inches, feet), that wont work, you can send by reference so you can change the data and not return a value.
Thats just to start, have you tried to compile this?
Yea, I got over 38 errors. If someone could just please fix this small program for me, then I'll at least have an idea of how to correctly do the rest of my programming projects, because right now I haven't even started on the others since I can't get this one to work. I literally have almost no time to use the computer every week cuz I work full time grave shifts, so I sleep after school, and I have other classes to worry about that I at least know how to do the work. So if nobody is able to help me, then I'll just have to drop this class with a W again. Paying the bills and trying to take classes for my engineering major is so hard for me right now, because literally nobody IRL is helping me out.

I can't learn how to do something until someone shows me how to do it right. You can't tell me to build a bridge or play a guitar song and expect me to be able to do it, I need to see someone do it right in front of me, correctly, you know what I mean? How can I know how to make this program right if I don't even know what a working program like this looks like? All I know how to do is printf and scanf, and even those things are hard to make work in my programs sometimes.
Here, I'll show you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>

void getInchesFeet(float*,float*);
float getTotalInches(float,float);
float inchToCMeter(float);
float inchToMeter(float);

int main (void){
	float inches,feet,totInches;
	getInchesFeet (&feet,&inches);
	printf("%6.3f feet and %6.3f inch(es) is equal to:\n", feet, inches);
	printf("%6.3f inches\n",totInches=getTotalInches(feet,inches));
	printf("%6.3f centimeters\n", inchToCMeter(totInches));
	printf("%6.3f meters\n", inchToMeter(totInches));
	getchar();
	return 0;
}

void getInchesFeet (float *feet, float *inches){
	printf("Welcome, please input the feet and and inches in \"n n\" format: ");
	char s[100];
	fgets(s,100,stdin);
	sscanf(s,"%f %f", feet, inches);
}

float getTotalInches(float feet, float inches){
	return feet*12+inches;
} // feetToInch

float inchToCMeter(float inches){
	return inches * 2.54;
} // inchToCMeter

float inchToMeter(float inches){	
	return inches * .0254;
} // inchToMeter  
Last edited on
Wow thank you so much, that really helps me out. I'm starting to understand a little more about how functions and calls work.

However I'm not sure what the

char s[100];
fgets(s,100,stdin);
sscanf(s,"%f %f", feet, inches);

means. I deleted the first 2 lines of that part, took out the extra s in sscanf, and deleted the first s in the parentheses, and everything worked.

Also if you could please explain why void getInchesFeet(float*,float*); is different than the other functions and they're not void as well, and the use of the asteriks. In the meantime, I'll read through my book some more to try to find some answers myself if I can understand what I'm reading :P.
C functions take a number of arguments, and produce a result. In the case of getInchesFeet, there is no result. Instead we passed in a pointer, and modified the variables inches and feet. However, getTotalInches, inchToMeter, and inchToCMeter return a value, a 'float' or real number.
Topic archived. No new replies allowed.