short and long int

This is a discussion on short and long int within the C Programming forums, part of the General Programming Boards category; Hi, How should I let the short int divide the long int and return the float? Code: #include <stdio.h> void ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Unhappy short and long int

    Hi,

    How should I let the short int divide the long int and return the float?

    Code:
    #include <stdio.h>
    
    void main() {
    	short int __x;
    	long int y;
    	float z;
    	__x = 55h;
    	y = 60L;
    	z = (float)__x / (float)y;
    	printf("Hello world.\nPeter John and Tom.\n");
    	printf("%h + %l = %.2f.\n", __x,y,z);
    }
    It shows the following errors:

    syntax error : 'bad suffix on number'
    syntax error : missing ';' before identifier 'h'
    'h' : undeclared identifier

  2. #2
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    The 'h' is not required. The z was being assigned correctly but printf was causing the problem. If by h you mean hex then __x = 0x55.

    Code:
      short int __x;
      long int y;
      float z;
      __x = 55;
      y = 60L;
      z = (float)__x / (float)y;
      printf("%d + %ld = %.2f\n", __x,y,z);

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    thanks for your help

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Have a read of this .

    Also, variable names starting with an underscore are reserved for implementation use, so avoid using them yourself.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 04:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21