-
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
-
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
-
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.
-
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