Your Ad Here Your Ad Here
Results 1 to 10 of 10

Thread: C Questions

  1. #1
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Ok...finally got everything working

    Ok, what is %lf, %c, and %ld?

    Help me fast pleaseeeeeee

  2. Software & Hardware   -   #2
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    35
    Posts
    5,530
    i have not done c in ages but htey just look like the names of variables to me.

    how about showing us the code and we can tell ya.

  3. Software & Hardware   -   #3
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Hehe was hoping you would be here

    Actually I found out what they were (after extensive researching cough googling)

    #ld = LONG Digit (or double.... probably digit)
    #lf = LONG float (the L just tells you LONG..... you can use H and that would mean SHORT)
    #c = character....

    Actually, I'm making a basic C calculator. I'm almost done with it, but I do have some errors.... here's what I have now (by the way it's in spanish.... so you might not understand it much, but you would get the point)

    Code:
    void main()
    {
       double primero;
       double segundo;
       char operador = 0;
       int cont;
       double respuesta;
    
       printf("La mera calcu de Leksi\n\n");
    
       printf("Instrucciones:\n\n");
       printf("Para sumar, utilice la forma x+y\n");
       printf("Para restar, utilice la forma x-y\n");
       printf("Para multiplicar, utilice la forma x*y\n");
       printf("Para dividir, utilice la forma x/y\n");
       printf("Para elevar, utilice la forma x^y\n\n");
       
       printf("Por favor ingrese la operacion a realizar\n");
       scanf("%lf %c %lf", &primero, &operador, &segundo);
    
       switch(operador)
       {
          case '+':
    	printf("Su respuesta es: ");
          	printf("%lf", primero + segundo);
          	break;
    
          case '-':
    	printf("Su respuesta es: ");
          	printf("%lf", primero - segundo);
          	break;
    
          case '*':
    	printf("Su respuesta es: ");
          	printf("%lf", primero * segundo);
          	break;
    
          case '/':
    	printf("Su respuesta es: ");
          	if(segundo == 0)
              printf("\n\n\aSu denominador no puede ser CERO\n");
             else
              printf("%lf", primero / segundo);
                break;
    
          case '^':
    	printf("Su respuesta es: ");
    	printf("%lf", pow (primero,segundo)); 
    	break;
      
          default:
          	printf("\n\aSu operacion no es correcta");
       }
    }
    Here's where I'm stuck at. The calculator works perfectly. For example, if you try "a+1" it gives you the "Incorrect operation" error. However, if the second term is something else (such as 1+a), it would take the second as 0 and give you 1 as the answer. Any ideas? Thanks

  4. Software & Hardware   -   #4
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Ok, yea I just tried everything with something else as the second number (1+a, 1-a, 1*a, 1/a, 1^a) and every time the a is taken as a 0 (zero).

    Could this be because of the default?

  5. Software & Hardware   -   #5
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Formatted output: printf description
    The format string given to the `printf' function may contain both ordinary characters (which are simply printed out) and conversion characters (beginning with a percent symbol, %, these define how the value of an internal variable is to be converted into a character string for output).

    Here is the syntax of a conversion specification:

      %{flags: - + space 0 #}{minimum field width}{.}{precision}{length modifier}{conversion character}

    Flags: `-' means left-justify (default is right-justify), `+' means that a sign will always be used, ` ' prefix a space, `0' pad to the field width with zeroes, '#' specifies an alternate form (for details, see the manual&#33. Flags can be concatenated in any order, or left off altogether.
    Minimum field width: the output field will be at least this wide, and wider if necessary.
    '.' separates the field width from the precision.
    Precision: its meaning depends on the type of object being printed:
    Character: the maximum number of characters to be printed.
    Integer: the minimum number of digits to be printed.
    Floating point: the number of digits after the decimal point.
    Exponential format: the number of significant digits.
    Length modifer: `h' means short, or unsigned short; `l' means long or unsigned long; `L' means long double.
    Conversion character: a single character specifying the type of object being printed, and the manner in which it will be printed, according to the following table:
    Character Type    Result

      d,i    int    signed decimal integer
        o      int    unsigned octal (no leading zero)
      x, X    int    unsigned hex (no leading 0x or 0X)
        u      int    unsigned decimal integer
        c      int    single character
        s      char *  characters from a string
        f      double  floating point [-]dddd.pppp
      e, E    double  exponential [-]dddd.pppp e[=/-]xx
      g, G    double  floating is exponent less than -4, or >= precision
                      else exponential
        p      void *  pointer
        n      int *  the number of characters written so far by printf
                      is stored into the argument (i.e., not printed)
        %              print %
    Got that from around

  6. Software & Hardware   -   #6
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Great - oh well.

    Now I have to do a project. Either a text editor (such as notepad) or a game (Galaga). If you have any ideas on how to do this, please let me know. If you find any programs around, please let me know so I can get ideas from it. I'm lost and I have to send in a part of the program tonight. So I'm in a hurry

    Thanks

  7. Software & Hardware   -   #7
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    bump


  8. Software & Hardware   -   #8

  9. Software & Hardware   -   #9
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Originally posted by shn@23 January 2004 - 20:48
    http://www.bluemug.com/research/text.pdf
    Cool, thanks for that. I'll see what I can do

  10. Software & Hardware   -   #10
    BANNED
    Join Date
    Jul 2003
    Location
    Guatemala
    Posts
    4,097
    Bump

    Any help on the game? The Galaga-type of game looks easier, although I have no idea how to make a cycle for the ship to move using gotoxy(x,y)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •