Thread: Starting Out

  1. #1
    Registered User Toireht's Avatar
    Join Date
    Apr 2006

    Starting Out

    Hi, brand new to programming and the site so far seems to have helped a lot. Just started today and finished my first little program, which converts celsius and fahrenheit. It seems like I can learn the basic stuff to get started from this website but after that I was looking at getting a book, which one would you guys recommend?

    If you have any tips please help me.

    #include <stdio.h>
    int main()
        int  y;    
                      "Temperture Converter\n"
        while(1) {      
            printf("1:)Fahrenheit to celsius\n");
            printf("2:)Celsius to fahrenheit \n");
            scanf("%d", &y);   
                if(y==1 || y==2){    
                else {   
                    printf("\n%d is not 1 or 2, please try again\n", y);
        if (y == 1) {   
            int uent, sol; 
            float frac; 
            frac = .555555556;  
            printf("Please enter the fahrenheit temperture:\n"); 
            scanf("%d", &uent); 
            sol = frac*(uent-32);  
            printf("The temperture in celsius is: %d\n", sol); 
        else if (y == 2) { 
            int uent, sol; 
            float frac; 
            frac = 1.8; 
            printf("Please enter the celsius temperture:\n"); 
            scanf("%d", &uent); 
            sol = (frac*uent)+32; 
            printf("The temperture in fahrenheit is: %d\n\n", sol); 
        return 0;

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    It the C board there is a sticky titled C Book Recommendations. Look in there, you'll get a good selection.
    Sent from my iPadŽ

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    I wrote a tip on this suggestion but it hasn't been posted yet. There are better ways to get numbers from the user than using scanf() but if you want to use it, you should check the return value. Scanf() returns the total number of data fields it was able to read in correctly. You should loop your program until scanf() succeeds.

    /* For example: */
    int y;
    do {
       printf("Enter a tempurature:");
       /* You will have to flush stdin somehow, with a function that your compiler provides. 
        *  _flushall() is NOT a standard C function. */
    } while ( scanf("%d", &y) != 1);
    I suggest you take a look at the FAQ for tips about getting numbers from the user. That's it, really. You could do other things, but I don't want to load you down with too much while you're still learning the language.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Doesn't anybody read FAQ's anymore?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting programs
    By Molokai in forum C Programming
    Replies: 1
    Last Post: 04-16-2009, 10:10 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  4. question about reading inputs starting with 0
    By jibbles in forum C Programming
    Replies: 8
    Last Post: 08-09-2004, 03:27 AM
  5. 12 year old starting...
    By Xterria in forum Game Programming
    Replies: 2
    Last Post: 09-24-2001, 07:33 PM