Thread: Runtime problem

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    Runtime problem

    Hello I wrote this code it's meant to convert a mathematical from 1 form to another but I cannot enter the numarator and the denominator sepeartly please help me as I'am out of ideas of what to do to solve it.

    Code:
    #include <stdio.h>
    
    
    int main()
    {
    	char z,w,G,num,den;
    	float Ts;
    	
    w=z-1/Ts;
    
    G=num/den;
    
    printf("Please enter the samplling rate: ");
    scanf("%f",&Ts);
    	
    printf("Please enter the numarator in terms of w: ");
    scanf("%c",&num);
    
    printf("Please enter the denominator in terms of w: ");
    scanf("%c",&den);
    
    printf("The discrete transfer function in the form of Z is %c \n",G);
    
    return 0;
    }

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    %c is for a character. That is, if you enter the number 5, it will read the character '5', which probably translates to the value 53 on most systems. You're better off just using an int type and %d.

    Also, why are you assigning w dependent on the values of the not yet initialised values of Ts and z?

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    also change the data type of those variables from char to int. %d works with pointers to int, not pointers to char.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    %d works with pointers to int, not pointers to char.
    That's why I said "You're better off just using an int type and %d"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM