# Thread: Help with C programming Mathematical Calculations

1. ## Help with C programming Mathematical Calculations

I have been doing c programming for about 3 days now and am pretty confused as to why this is not working. It basically is asking to estimate the temp inside a freezer after a certain time (t) power outage...

here is what i have so far, anyhelp is appreciated...

[tag]
Code:
```
#include <stdio.h>
int
main(void)

{

int time; /*time */
int temp; /* temperature */

printf("EE233 Spring 2010, P1: Power Failure Freezer Temperature Estimate."); /*Greeting */
printf("How long (hours and minutes) since the power failure to the freezer?>");
scanf("%d", &time);
temp = (4*(time*time)/( time +2))-20; /*Calculate the temperature */
printf("The estimated temperature inside your freezer is %d degrees Celsius.", temp );

return (0);
}```
[/tag]

Not asking anyone to do this for me, just give me some hints on where to make this thing work...

Thanks for any help.

2. Well it's hard to answer that question without knowing what's wrong with it. If your math is off I'd recommend making temp a double. And then use double values in your math and your compiler will automatically do casting as necessary:

Code:
```double temp;

/*....*/

temp = (4.0*(time*time)/( time +2.0))-20.0;```

3. Your equation needs to use either hours or minutes or some ONE unit of time. You've confused the poor equation!

"hours and minutes"

time * time

You know better!

4. Ok, i've been working on this a bit and this is what i have now... still have a couple errors:

1) Warning 1 warning C4313: 'printf' : '%d' in format string conflicts with argument 1 of type 'char [79]' c:\documents and settings\fst50svt\my documents\visual studio 2005\projects\p1\p1\p1.c 25

2)Warning 2 warning C4313: 'printf' : '%d' in format string conflicts with argument 2 of type 'char [79]' c:\documents and settings\fst50svt\my documents\visual studio 2005\projects\p1\p1\p1.c 25

3)Error 3 error C2296: '&' : illegal, left operand has type 'int *__w64 ' c:\documents and settings\fst50svt\my documents\visual studio 2005\projects\p1\p1\p1.c 27

4) Error 4 error C2065: 'time' : undeclared identifier c:\documents and settings\fst50svt\my documents\visual studio 2005\projects\p1\p1\p1.c 29

Here is the code...

Code:
```#include <stdio.h>
#define HOUR 60 //conversion constant

int
main(void)

{

int hour=0; //hour input
int minutes=0; //minute input
double temp=0; //temperature output

printf("EE233 Spring 2010, P1: Power Failure Freezer Temperature Estimate. \n"); //Greeting
printf("How long (in hours and minutes) since the power failure to the freezer?> %d %d"); //prompts for input from user

scanf("%d" "%d", &hour &minutes); //input from user in hours and minutes

time = hour + minutes; //convert hours to minutes

temp = ((4*(time*time)/(time+2))-20); //Calculate the temperature
printf("The estimated temperature inside your freezer is %3.1f degrees Celsius.", temp); //displays results

return (0);

}```

5. The first two are because of this red part:
Code:
`printf("How long (in hours and minutes) since the power failure to the freezer?> %d %d");`
The & error is probably because of this red part:
Code:
`scanf("%d" "%d", &hour &minutes);`
WRT to using scanf(), make sure you read and understand this:
STDIN pitfalls

I'm gonna let you contemplate what this might mean:
'time' : undeclared identifier
...if you really don't get it, ask again

6. Originally Posted by MK27
The & error is probably because of this red part:
Code:
`scanf("%d" "%d", &hour &minutes);`
If you put two string literals next to each other, the preprocessor merges them into a single literal. That part's okay, if a bit weird. What I see there is a missing comma between &hour and &minutes.

7. Originally Posted by StangFan
I have been doing c programming for about 3 days now and am pretty confused as to why this is not working. It basically is asking to estimate the temp inside a freezer after a certain time (t) power outage...
I've hilighted the problem in bold above. Never ever under any circumstance, just say that something "is not working" or "does not work", or "did not work" in a programming forum.
It's the most useless, fustrating, and downright infuriating thing you can do.
Instead, always explain in detail exactly what happens, or what errors you get!

8. Originally Posted by MK27
The first two are because of this red part:
Code:
`printf("How long (in hours and minutes) since the power failure to the freezer?> %d %d");`
The & error is probably because of this red part:
Code:
`scanf("%d" "%d", &hour &minutes);`
WRT to using scanf(), make sure you read and understand this:
STDIN pitfalls

I'm gonna let you contemplate what this might mean:
'time' : undeclared identifier
...if you really don't get it, ask again
i need to put double time; up at the top?