Thread: I don't know how to slove these simple questions

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    4

    Question I don't know how to slove these simple questions

    HI...this is my first post and I hope to reach a 1000
    can you help me to get answers?I am learning C from "Problem Solving and Program Design In C" book ( nice one)

    ---------------------
    1. Write a program to read an int type value of temperature in degree Celsius and convert it into Fahrenheit. Use the following formula:

    F = (9/5 * C) + 32



    2. Write a program to read a double type value of temperature in Fahrenheit and convert it into degree Celsius. Use the following formula: C = 5/9 (F – 32).



    3. Write a program, to read two integer numbers and finds their sum, difference, product, quotient, and average.



    4. Write a program that reads 5 characters from user one by one, and then displays them together (on the same line). The program output should look like as shown below:



    Enter 1st character: B

    Enter 2nd character: A

    Enter 3rd character: S

    Enter 4th character: I

    Enter 5th character: M



    You entered: BASIM

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    have you even tried it yet?
    its very simple.

    give it a go first
    there are only 10 people in the world, those who know binary and those who dont

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    I tried it this way...what is wrong with it?...also I have a question....what is the standard structure to make a program?I know that preprocessor directives come first and then the reserved words right?the book doesnt explain it
    --------------------------------------------
    }
    Code:
    ##include <stdio.h>
    int 'C' 'F'
    main (void)
    {
    	printf("Today's Temp");
    
    		scanf("%d" ,%Feh);
    F=(9/5*C)32
    
    printf("F is");
    return (0)'

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    596
    Code:
    
    #include <stdio.h> /* only one # */
    
    /* Don't declare your variables here  unless you have a reason to do so.
    That would make them global variables.
    Instead, make them local variables by declaring them inside the main function. */
    
    main (void)
    {
         int C, F; /*note: no quotes, and there must be a semicolon at end of each line
    (EXCEPT preprocessor directives */
         printf("Enter today's temp in Celsius > ");
         scanf("%d",&C);  /* What's Feh?  You want to input a value for C. 
    And note, it's &C, not %C */
         F=(9/5*C)+32;
         printf("F is ");
         printf("%d", F); /* Note, in printf, no & before the variable name*/
         return 0;
    }

  5. #5
    root
    Join Date
    Sep 2003
    Posts
    232
    >I am learning C from "Problem Solving and Program Design In C" book ( nice one)
    Obviously not if your not reading it. A quick glance into any book on C will show you your syntactical errors. It's cool, you can even find syntax errors in books if you look carefully. You don't even have to look carefully in some books.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    what is worng with this one?it gives an error about..I know alot of things after I have read the book my problem is how to start making the code or the program


    C:\Documents and Settings\zaki\Desktop\hih\Cpp1.cpp(14) : error C2146: syntax error : missing ';' before identifier 'printf'

    Code:
    #include <stdio.h>
    
    void main (void)
    
    {
    	int c,f;
    	
    	printf("from celecus to fahern");
    	
    	printf("enter c");
    	scanf("%d,&c");
    	f=(9/5*c)+32
    	
    	printf("it's gonna be %d,f");
    
    
    }

  7. #7
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    you need a ; when you asign values to variables.

    Code:
    f=(9/5*c)+32;
    and this
    [code]
    Code:
    printf("it's gonna be %d,f");
    should be
    Code:
    printf("it's gonna be %d",f);
    Last edited by Shogun; 10-03-2003 at 11:45 AM.
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    4
    Originally posted by Shogun
    you need a ; when you asign values to variables.

    Code:
    f=(9/5*c)+32;
    and this
    [code]
    Code:
    printf("it's gonna be %d,f");
    should be
    Code:
    printf("it's gonna be %d",f);
    I did all that 15 minutes ago...I reiece no errors but only one warning....and when I excute the program..the DOS window will appear I enter a value and then the program crashes...the warning is
    warning C4700: local variable 'c' used without having been initialized
    Linking...

    my head will blow up...8 hours on a silly program..I want to die

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Code:
    scanf("%d,&c");
    should be
    Code:
    scanf("%d",&c);

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by zaki
    what is worng with this one
    Code:
    void main (void)
    Main does not return void. It always returns and int. If your book uses this, don't. Change it to return an integer. It's wrong otherwise. Look in the FAQ if you want more info on it, or search the board for void main.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A couple questions
    By Flakster in forum C++ Programming
    Replies: 7
    Last Post: 08-09-2005, 01:22 PM
  3. Few simple questions...
    By Shane in forum C++ Programming
    Replies: 9
    Last Post: 08-06-2005, 02:40 AM
  4. A few simple batch questions
    By sean in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 07-02-2003, 01:35 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM