-1

Possible Duplicate:
Why can’t decimal numbers be represented exactly in binary?

#include <stdio.h>

int main(void)
{
    int temperature, time;
    float minutes;

    printf("What is the Fahrenheit temperature?\n");
    scanf("%d",&temperature);

    time = (5 - (temperature - 90) / 5);
    minutes = ((5 % time) * 60);


    if (temperature >= 90)
        printf("It will rain at approximately %d hours and %f minutes after noon.\n", time, minutes);

    else
        printf("It will not rain today.\n");


    system("PAUSE");
    return 0;

}

I am using the C programming language. This is homework but its okay to use some bits from the web as long as its not the whole code. Anyways, If the current temperature is 93f time = 4.4 so I would like to output:

It will rain approximately 4 hours and 24 minutes after noon but the output instead is:

It will rain at approximately 5 hours and 0.000000 minutes after noon

EDIT: I get an error now that states invalid operands to binary % (have int and float) Please be patient with me LOL I am trying to learn.

#include <stdio.h>

int main(void)
    {
    int current_temp;
    float remaining_minutes, time;

    printf("What is the temperature in Fahrenheit?\n");
    scanf("%d",&current_temp);

    time = (5 - (current_temp - 90) / 5);
    ERROR**** remaining_minutes = ((5 % time) * 60);


    if (current_temp >= 90)
        printf("It will rain at approximately %d hours and %f minutes after noon.\n", time);

    else
        printf("It will not rain today.\n");


    system("PAUSE");
    return 0;



}
Community
  • 1
  • 1
anon_nerd
  • 1,251
  • 1
  • 10
  • 16

4 Answers4

0

You need to define your time as a float as well. Right now you are dividing integers by integers so you are only getting whole numbers.

Sean Perry
  • 3,776
  • 1
  • 19
  • 31
  • I tried to. I added new edited code but it didn't work. Can you please explain more. I would really appreciate it. – anon_nerd Oct 11 '12 at 21:08
0

How about mins = (time % 1) * 60?

Edit: or mins = (time*10 % 10) * 6. On my phone so can't really test.

Stoof
  • 687
  • 2
  • 6
  • 12
0

time is an int. You can't expect it to hold a floating point number.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
0

time = (5 - (temperature - 90) / 5);

time,5,90 are integers so time = 5 - 0 ...wich is 5

trie to use float time and

time = (5.0 - (float)(temperature - 90) / 5);
Adrian Herea
  • 658
  • 6
  • 7