Thread: short and long int

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