vkcelik 0 Newbie Poster

Hi. I am making a program to graph quadratic equations using arrays. I got it working drawing the equation when a=1, b=7 and c=5 and with the limits -8 to 1.. But then I wanted to add a functionality so that the graph was scaled down if couldn't fit in the array. So i changed the code and now when i try to draw the above equation it is just drawed as a straight line..

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

const char ae = -111; //lille æ 
const char oe = -101; //lille ø 
const char aa = -122; //lille å 
const char iAnden = -3;

int main()
{    
    float ymin=0, ymax=0;
    int y, start, slut, a ,b ,c;
    

        cout << "Indtast en andengradsligning i formen: ax" << iAnden << " + bx + c" << endl;
        cout << "Indtast a:" << endl;
        cin >> a;
        cout << "Indtast b:" << endl;
        cin >> b;
        cout << "Indtast c:" << endl;
        cin >> c;
    
        cout << "Indtast startinterval:" << endl;
        cin >> start;
        cout << "Indtast slutinterval:" << endl;
        cin >> slut;

        cout << endl;
        char koor [28][28];
        
        //arrayet cleares
        for(int i=0; i<28; i++)
        {
        for(int j=0; j<28; j++)
        {
        koor[i][j]=' ';
        }
        }
        
        //akserne laves
        for(int i=0; i<28; i++)
        {
        koor[i][14]='|';
        }
        for(int j=0; j<28; j++)
        {
        koor[14][j]='-';
        }
        koor[14][14]='+'; 
        koor[14][27]='>';
        koor[0][14]='^';
        
        for(int x=start; x<=slut; x++)
        {
        y=a*x*x+b*x+c;
      
          if(y>ymax)
          {
          ymax=y;
          }
          else if(y<ymin)
          {
          ymin=y;
          }
        }
        
      int scale, ytegn;
      scale=(int)((ymax-ymin)/28+1);
      
        for (int x=start; x<=slut; x++)
        {
            ytegn=(int) ((a*x*x+b*x+c-ymin)/scale);
            koor[14-y][x+14]= '*';
        }
        
        //arrayet udskrives
        for(int i=0; i<28; i++)
        {
                for(int j=0; j<28; j++)
                {
                        cout << koor[i][j];
                }  
        cout << endl;
        }
        
        system("pause");
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.