GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Aug-2008, 11:12
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past
Smile

C program for temperature calculation


hi i am new here please forgive me if i have violate any rules and let me know of my mistake in order to rectify it .
OK
first of all i am trying to make simple program in c for converting temp from Fahrenheit to Celsius and vice versa but cant figure out my mistakes please help i am a newbie in programming so please explain so that i can understand.
here is the program i wrote

CPP / C++ / C Code:
#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
float a,b;
char f,c;
printf("Enter c for centigrade and f for farenhight");
scanf("%c",&c);
if(c=='c')
{
printf("enter the temp in centigrade")
scanf("%f",&a);
b=(((a-32)*5)/9);
clrscr();
printf("The required temp in farenhight is : %f",b);
getch();
}
else
{
scanf("%c",&f);
if(f=='f')
{
printf("enter the temp in farenhight")
scanf("%f",&a);
b=(32+(9*a)/5);
clrscr();
printf("The required temp in centigrade is : %f",b);
getch();
}
else
printf(" please enter as per instructed")
getch();
}
Last edited by admin : 05-Aug-2008 at 21:12. Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
  #2  
Old 05-Aug-2008, 12:05
Howard_L Howard_L is offline
Senior Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 1,007
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: c program for temp calculation


Are you getting warnings or errors when you compile? If not learn to set them to maximum. on your compiler. They will help you.
Will the program run?
Post us the ouptuts so we can see what you see!
...and give a s good a description of problem as you can.
Enclose output using the 'code' tag icon thingy in the posting input window.
Here some starter suggestions:
CPP / C++ / C Code:
/* I used the compile line:
gcc -Wall -W -pedantic temperature-gid080805.0.c -o temperature-gid080805.0 */

/* #include <conio.h>  ...don't use, keep code compilable on more platforms 
                 ...so you'll need to change occurances of getch() to getchar()
   clrscr();    ...also not cross platform , replace with a line or something
like: */

printf("\n************\n");

int main(){              /* <--  Use a return type for main(): */
     program stuff();
  return 0;              /* <-- return value at end of program */
}
 
/* temperature-gid080805.0.c:7: warning: ISO C90 forbids mixed declarations and code 
Move  variable declarations to top of bracketed scope before statements: */
int main(void)
{ 
  float a, b;
  char  f, c;
  statementstuff();
  ...

/* temperature-gid080805.0.c:14: error: expected ‘;’ before ‘scanf’
    printf("Enter the temp in centigrade")      NO */
    printf("Enter the temp in centigrade: ");   /* YES    

temperature-gid080805.0.c:36: warning: control reaches end of non-void function

  uh ohh... closing brackets not matching opening brackets somewhere, 
  print out the code on paper and check flow with a pencil!
 fix test fix test fix test fix test fix test fix test fix test fix...
*/
Last edited by Howard_L : 05-Aug-2008 at 13:09.
  #3  
Old 06-Aug-2008, 07:50
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past
Smile

Re: C program for temperature calculation


while i am compiling i am getting the error

Code:
Miracle C Compiler (r3.2), written by bts. Compiling f:\xxx.c main f:\xxx.c: line 5: Parse Error, expecting `'}'' 'float a,b' aborting compile
  #4  
Old 06-Aug-2008, 07:52
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


please explain clearly cant understand or if possible give the corrected code
  #5  
Old 06-Aug-2008, 08:31
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 6,153
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: C program for temperature calculation


Quote:
Originally Posted by deadly disaster
please explain clearly cant understand
Here's the message, from your previous post:
Quote:
Originally Posted by deadly disaster
f:\xxx.c: line 5: Parse Error, expecting `'}''
I'm not sure how much more clear the compiler could be or how much more clear I can make it. I do know that when you are just getting started it can be confusing. Really. See Footnote.

So, here goes:

The compiler was looking for a closing '}' brace when it reached the end of the file. The compiler is also telling you that the block that wasn't closed started somewhere around line 5.

You could, maybe, see it more clearly if you indent your code to emphasize the structure. The compiler ignores indentation, but us mere humans can benefit by adapting some kind of style. Look at examples in books or in examples on the web.

Here's your code indented according to my personal preference style.
CPP / C++ / C Code:
#include <stdio.h>
#include <conio.h>
main()
{
    clrscr();
    float a, b;
    char f, c;
    printf("Enter c for centigrade and f for farenhight");
    scanf("%c", &c);
    if (c == 'c') {
        printf("enter the temp in centigrade")
        scanf("%f", &a);
        b = (((a - 32) * 5) / 9);
        clrscr();
        printf("The required temp in farenhight is : %f", b);
        getch();
    }
    else {
        scanf("%c", &f);
        if (f == 'f') {
            printf("enter the temp in farenhight")
            scanf("%f", &a);
            b = (32 + (9 * a) / 5);
            clrscr();
            printf("The required temp in centigrade is : %f", b);
            getch();
        }
        else
            printf(" please enter as per instructed")
            getch();
    }

What's missing? The closing '}' at the end.

I am curious about why "Fahrenheit" is spelled correctly in the problem statement, but is consistently misspelled in the code that you wrote? Also why did you downgrade the preferred term "Celsius" to the old-fashioned, unofficial, designation "centigrade" in the code?

Oh, well...

Quote:
Originally Posted by deadly disaster
or if possible give the corrected code
Work past this big problem and go to the next. In fact, there are numerous other problems. Look at your compiler messages and see if you can tell what the heck it is talking about. I know it's not always easy, but try. If you have further questions, ask. Be sure to tell us the exact message(s).

Regards,

Dave

Footnote: No one was born knowing this stuff, you know...
---davekw7x
  #6  
Old 07-Aug-2008, 10:24
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


thank you dave for such quick response
  #7  
Old 07-Aug-2008, 10:27
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


for my spelling mistake i am sorry as because it is not my mother language i am a bit weak in it the spelling is correct in the post because of the automated spelling check process.
  #8  
Old 07-Aug-2008, 10:30
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


i am just a beginner in c language and also don`t much about it .
i have learned till now some basic functions in the c language.
  #9  
Old 07-Aug-2008, 10:35
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


so dave can you suggest me a better way for my program .

also can you suggest me some examples which can be easily understandable
for a beginner.

so that i can learn the language fast and easy and effective way.
  #10  
Old 07-Aug-2008, 10:36
deadly disaster deadly disaster is offline
Junior Member
 
Join Date: Aug 2008
Posts: 34
deadly disaster has a little shameless behaviour in the past

Re: C program for temperature calculation


by the way i am very much thankful for quick and generous response.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 09:24
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
Help with a complex program lordfuoco C++ Forum 5 24-Jun-2006 06:03
Grades Calculation Program UnWarierMage C++ Forum 11 19-Jun-2006 15:24

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:14.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.