Thread: please help me

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    7

    please help me

    Before High resolution graphic displays became common, computer terminals were often used to display graphs of equations using only text characters. A typical
    technique was to create a vertical graph by spacing over on the screen, then displaying an *. Write a program that displays the graph of an increasing frequency sine wave this way. The program should ask the user for an initial step-size in degrees and the number of lines of the graph to display.

    that was my assignment, and i'm almost done, but i got serveral error messages and i don't know how to fix my program, please help me

    /* This program wlil graph an increasing frequency sine wave */

    #include <stdio.h> /* printf, scanf definitions */
    #include <math.h> /* math definitions */
    #define pi 3.14159

    int
    main(void)
    {
    double stepsize; /* input - stepsize */
    double first_value; /* input - first value */
    double number_of_lines; /* input - number of lines */
    double output;
    double loop;
    double scale;
    double increment;
    double y;
    double sin;

    /* Get the step size, first value, and number of lines */
    printf("Enter the inial step size> ");
    scanf("%d", &stepsize);
    printf("Enter the first value> ");
    scanf("%d", &first_value);
    printf("Enter the number of lines> ");
    scanf("%d", &number_of_lines);

    for (int i = 0; i<number_of_lines; ++i)
    {
    double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));
    y *= 10.0; /* Scaling */
    y += 5.0; /* Scaling */

    /* Output y spaces by using loop */
    for (int j = 0; j < y; ++j)
    {
    printf(" ");
    }
    printf("*\n"); /* Output '*' and new line) */
    }
    return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    http://cboard.cprogramming.com/showthread.php?t=25765
    How big does << !! Posting Code? Read this First !! >> have to be before you read it?
    Now click the nice "edit" button at the bottom of your post and try again.

    > but i got serveral error messages
    Well keeping them a secret won't help - post them
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    typo with this variable
    Code:
    double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));
    look at what you are passing to sin()
    Code:
    double y = sin(exp(first_value + i * stepsize * 2 * pi / 180));

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    7
    Code:
    /* This program wlil graph an increasing frequency sine wave */
            
    #include <stdio.h>                      /* printf, scanf definitions */
    #include <math.h>                       /* math definitions          */
    #define pi 3.14159
            
    int
    main(void)
    {
            double stepsize;                /* input - stepsize     */
            double first_value;             /* input - first value  */
            double number_of_lines;         /* input - number of lines */
            double output;
            double loop;
            double scale;
            double increment;
            double y;   
            double sin;
            
            /* Get the step size, first value,  and number of lines */
            printf("Enter the inial step size> ");
            scanf("%d", &stepsize);
            printf("Enter the first value> ");
            scanf("%d", &first_value);
            printf("Enter the number of lines> ");
            scanf("%d", &number_of_lines);
    
            for (int i = 0; i<number_of_lines; ++i)
    {
            double y = sin(exp(first_value + i * stepsize * 2 * pi / 180));
            y *= 10.0; /* Scaling */
            y += 5.0;  /* Scaling */
    
            /* Output y spaces by using loop */
            for (int j = 0; j < y; ++j)
    {
            printf(" ");
    }
            printf("*\n"); /* Output '*' and new line) */
    }
            return 0;
    }
    code tags added by Kermi3

    i'm still getting these error messages...

    sine.c: In function `main':
    sine.c:28: error: `for' loop initial declaration used outside C99 mode
    sine.c:30: error: called object is not a function
    sine.c:35: error: `for' loop initial declaration used outside C99 mode[SIZE=5]

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    31
    Code:
    /* This program wlil graph an increasing frequency sine wave */
    
    #include <stdio.h>                      /* printf, scanf definitions */
    #include <math.h>                       /* math definitions          */
    #define pi 3.14159
    
    int
    main(void)
    {
            double stepsize;                /* input - stepsize     */
            double first_value;             /* input - first value  */
            double number_of_lines;         /* input - number of lines */
            double output;
            double loop;
            double scale;
            double increment;
            double y;
            double sin;
    
            /* Get the step size, first value,  and number of lines */
            printf("Enter the inial step size> ");
            scanf("%d", &stepsize);
            printf("Enter the first value> ");
            scanf("%d", &first_value);
            printf("Enter the number of lines> ");
            scanf("%d", &number_of_lines);
    
            for (int i = 0; i<number_of_lines; ++i)
    {
            double y = sin(exp(first__value + i * stepsize * 2 * pi / 180));
            y *= 10.0; /* Scaling */
            y += 5.0;  /* Scaling */
    
            /* Output y spaces by using loop */
            for (int j = 0; j < y; ++j)
    {
            printf(" ");
    }
            printf("*\n"); /* Output '*' and new line) */
    }
            return 0;
    }
    I havent changed a thing. just used the code thingy to make it look nicer for others

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Can you not read the huge bold letters from salem well just in case let me do it agian
    << !! Posting Code? Read this First !! >>
    << !! Posting Code? Read this First !! >>
    << !! Posting Code? Read this First !! >>
    << !! Posting Code? Read this First !! >>
    << !! Posting Code? Read this First !! >>
    << !! Posting Code? Read this First !! >>
    Heres the nice link for that little post

    http://cboard.cprogramming.com/showthread.php?t=13473

    for crying out loud read it
    Last edited by prog-bman; 10-10-2004 at 10:25 AM.
    Woop?

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    7
    oh...i didn't know what salem was talking about...thanks...please help me with my errors

  8. #8
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Quote Originally Posted by my_username1234
    i'm still getting these error messages...
    and just a *few* others I bet..

    Ok, first - declaring a variable inside a for loop is ok in C99, but not outside.

    Second, are you trying to call sin()? Then you need to get rid of the variable sin

    Code:
    double sin;
    Last edited by kermit; 10-10-2004 at 10:42 AM.

  9. #9
    Registered User
    Join Date
    Oct 2004
    Posts
    7
    Code:
    /* This program wlil graph an increasing frequency sine wave */
    
    #include <stdio.h>                      /* printf, scanf definitions */
    #include <math.h>                       /* math definitions          */
    #define pi 3.14159
    
    int
    main(void)
    {
            double stepsize;                /* input - stepsize     */
            double first_value;             /* input - first value  */
            double number_of_lines;         /* input - number of lines */
            double output;
            double loop;
            double scale;
            double increment;
            double y;
            double sin;
    
            /* Get the step size, first value,  and number of lines */
            printf("Enter the inial step size> ");
            scanf("%d", &stepsize);
            printf("Enter the first value> ");
            scanf("%d", &first_value);
            printf("Enter the number of lines> ");
            scanf("%d", &number_of_lines);
    
            for (int i = 0; i<number_of_lines; ++i)
    {
            double y = sin;
            (exp(first_value + i * stepsize * 2 * pi / 180));
            y *= 10.0; /* Scaling */
            y += 5.0;  /* Scaling */
    
            /* Output y spaces by using loop */
            for (int j = 0; j < y; ++j)
    {
            printf(" ");
    }
            printf("*\n"); /* Output '*' and new line) */
    }
            return 0;
    }
    and these are the only errors i have left, please help me fix it...i don't know how

    sine.c:28: error: `for' loop initial declaration used outside C99 mode
    sine.c:36: error: `for' loop initial declaration used outside C99 mode

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > for (int i = 0; i<number_of_lines; ++i)
    Like the message says - this isn't legal syntax for your C89 compiler.

    int i; // at the start of the block

    for (i = 0; i<number_of_lines; ++i) // like this
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    I am assuming you are not the author of this code...

    As I referred to before, you have lines like this:
    Code:
    for (int j = 0; j < y; ++j)
    Notice that the variable j is being declared inside the loop. This is ok for the C99 standard, but not in C89. Either declare it outside, with all of your other variables, or use the -std=c99 flag when you compile (if you are using gcc). I think the preference would be the former choice.

    edit - curses, foiled again!
    ~/
    Last edited by kermit; 10-10-2004 at 12:33 PM.

  12. #12
    Registered User
    Join Date
    Oct 2004
    Posts
    7
    ahhh! the program is supposed to draw an increasing frequency sine function, but all i get is "*"

    Code:
    /* This program wlil graph an increasing frequency sine wave */
    
    #include <stdio.h>                      /* printf, scanf definitions */
    #include <math.h>                       /* math definitions          */
    #define pi 3.14159
     
    int
    main(void)
    {
            double stepsize;                /* input - stepsize     */
            double first_value;             /* input - first value  */
            double number_of_lines;         /* input - number of lines */
            double output;   
            double loop;
            double scale;
            double increment;
            double y;
            double sin;
            double i;
            double j;
            /* Get the step size, first value,  and number of lines */
            printf("Enter the inial step size> ");
            scanf("%d", &stepsize);
            printf("Enter the first value> ");
            scanf("%d", &first_value);
            printf("Enter the number of lines> ");
            scanf("%d", &number_of_lines);
            
            for (i=0; i<number_of_lines; ++i) //
    {
            double y = sin;
            (exp(first_value + i * stepsize * 2 * pi / 180));
            y *= 10.0; /* Scaling */
            y += 5.0;  /* Scaling */
     
            /* Output y spaces by using loop */
            for (j=0; j < y; ++j) //
    {
            printf(" ");
    }
            printf("*\n"); /* Output '*' and new line) */
    }
            return 0;
    }

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why doesn't anyone ever listen to their compiler?
    m1234.c: In function `main':
    m1234.c:21: warning: int format, double arg (arg 2)
    m1234.c:23: warning: int format, double arg (arg 2)
    m1234.c:25: warning: int format, double arg (arg 2)
    m1234.c:11: warning: unused variable `output'
    m1234.c:12: warning: unused variable `loop'
    m1234.c:13: warning: unused variable `scale'
    m1234.c:14: warning: unused variable `increment'
    m1234.c:15: warning: unused variable `y'
    Where do you ever assign sin a value?
    Why do you have a variable named sin when the math library comes with a function named sin?
    What exactly is this supposed to do?
    Code:
    (exp(first_value + i * stepsize * 2 * pi / 180));
    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Registered User
    Join Date
    Oct 2004
    Posts
    7
    my compiler doesn't say any of those errors

  15. #15
    Registered User
    Join Date
    Oct 2004
    Posts
    31
    Quote Originally Posted by my_username1234
    my compiler doesn't say any of those errors
    try "gcc -Wall -ansi filename.c"
    to display all warnings

    EDIT: i.e if you are using UNIX

Popular pages Recent additions subscribe to a feed