Jump to content

Very basic help

- - - - -

  • Please log in to reply
3 replies to this topic

#1
ljl22

ljl22

    Newbie

  • Members
  • PipPip
  • 20 posts
#include<stdio.h>

int conv(int F);

int main()
{
int F;

for(F=0; F<300; F=F+20);
{
scanf("%d",&F);
printf("%d, ",F);
printf("%d\n",conv(F));
}
}

int conv(int F)
{
return (F-32)*(5/9);
}

I am new to programming, and have been set a task to print a table of Fahrenheit values and equivalent Celsius values. This code I have written doesn't seem to work and I'm not sure why?

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
Because you overwrite value of F when you read input (scanf function). And remove that semicolon after for. Also, in your converting function you have to multiply by floating point number because integer division of 5 / 9 is 0.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#3
ljl22

ljl22

    Newbie

  • Members
  • PipPip
  • 20 posts
Thank you--it's been driving me mad! I have actually got it spitting out values now, but every value after the comma is 0? I got rid of the scanf (don't think I needed it) and the semicolon after for, I think there's something wrong with my 'conv' function but I'm not sure what

#4
ljl22

ljl22

    Newbie

  • Members
  • PipPip
  • 20 posts
ahhh got it... thanks very much, it would have driven me mad




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users