Thread: graphs

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    Angry graphs

    i am trying this exercise and i dont know wot 2 do!

    Graphs are usually shown with the X axis as a horizontal and the Y axis as a vertical. As you will only be allowed to use a one-dimensional array in this coursework, the usual X and Y axis will need to be swapped around. Write a program that displays the graph of the following equation Y=2X+5 The program should first ask the user for:1. the X axis starting point 2. the number of steps3. step-sizeIt should then repeatedly calculate the value of Y using the changing value of X. Normally, X increases by the step size for the number of steps specified. The program should display an ‘*’ in each X column to denote the Y value, e.g. if Y = 10, then the 10th element of an 81 element character array should be set to ‘*’ and then the string Graphs are usually shown with the X axis as a horizontal and the Y axis as a vertical. As you will only be allowed to use a one-dimensional array in this coursework, the usual X and Y axis will need to be swapped around.

    Write a program that displays the graph of the following equation

    Y=2X+5

    The program should first ask the user for:

    1. the X axis starting point
    2. the number of steps
    3. step-size

    It should then repeatedly calculate the value of Y using the changing value of X. Normally, X increases by the step size for the number of steps specified. The program should display an ‘*’ in each X column to denote the Y value, e.g. if Y = 10, then the 10th element of an 81 element character array should be set to ‘*’ and then the string

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Please read the two first posts that appear at the top of this board, esspecialy regarding HOMEWORK, and then post again with some indication that you tried on your own. People here help much, much more once they see that you are putting effort into solving the problem yourself instead on blindly asking for answers,

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    2

    work ive done

    this is wot ive done

    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>

    #define GRAPH_SIZE 80

    main ()
    {

    int x;
    int y;
    int increment = 1;
    int counter;
    int steps;
    int size;
    char graph[GRAPH_SIZE];
    int counter2;

    printf ("Starting point of X Axis: ");
    scanf("%d", &x);

    printf ("Number of Steps: ");
    scanf("%d", &steps);

    printf ("Step Size: ");
    scanf("%d", &size);


    printf("--------------------------------------------------------------------------------");

    for(counter = 0 * size; counter < steps * size ; counter+= size)
    {
    y = (2 * x) + 5;


    for (counter2 = 0; counter2 <=80; counter2 ++)
    {


    if (counter2 == y)
    graph[counter2] = '*';
    else
    if (counter2 != y)
    graph[counter2] = ' ';
    if (y < 0)
    graph[0] = '0';
    else
    graph[0] = '|';

    }
    printf("%s", graph);
    }

    getch();

    return(0);


    }


    the problem is that the graph appears the axis on the left is indented, having a problem insertin the "+" sign.

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    thats great that you've tried, but you're posting on the wrong board, this is c++ not c. Also, please use code tags discribed in the "sticky" posts up top.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Graphs and the STL
    By smitsky in forum C++ Programming
    Replies: 1
    Last Post: 12-04-2004, 06:32 PM
  2. graphs and algorithms
    By Micko in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2004, 01:13 PM
  3. Generate Graphs
    By beet in forum C Programming
    Replies: 6
    Last Post: 08-19-2003, 07:14 PM
  4. graphs
    By res025ol in forum C++ Programming
    Replies: 0
    Last Post: 03-28-2002, 08:31 PM
  5. making graphs in C
    By kreyes in forum C Programming
    Replies: 6
    Last Post: 03-02-2002, 08:38 PM