an error in my code

this is my code

#include <iostream>
#include <cmath>
#include "graph1.h"

using namespace std;

int main()
{
//variables
int jan = 0;
int feb = 0;
int mar = 0;
int MAX_POSSIBLE_SALES = 10000;
int monthly_sales = 0;
int height = 0;
int height1 = 0;
int height2 = 0;
int total = 0;
int average = 0;
int obj_no = 0;


//Display graphics
displayGraphics();


//prompt the user to input
cout << "Enter January Sales: ";
cin >> jan;
cout << "Enter February Sales: ";
cin >> feb;
cout << "Enter March Sales: ";
cin >> mar;


//drawing the lines of the chart
drawLine (200, 50, 200, 250, 1);
drawLine (200, 250, 400, 250, 1);
//drawing the lines of the summary box

drawLine (200, 300, 200, 400, 1);
drawLine (200, 400, 400, 400, 1);
drawLine (200, 300, 400, 300, 1);
drawLine (400, 300, 400, 400, 1);

//placing everything in the chart
gout << setPos (225, 50) << "Sales For Jan - March" << endg;
gout << setPos (125, 130) << " US" << endg;
gout << setPos (125, 155) << " Dollars" << endg;
gout << setPos (200, 265) << "Jan " << "Feb " << "March" << endg;

//placing everything in the summary box
gout << setPos (205, 315) << "Summary" << endg;
total = (jan+feb+mar); //equation total sales
average = (total/3); //equation average sales
gout << setPos (205, 330) << "Total Sales: $" << total << endg;
gout << setPos (205, 345) << "Average Sales: $" << average << endg;


//equations for the height of the bars
height = (jan/MAX_POSSIBLE_SALES);
height1 = (feb/MAX_POSSIBLE_SALES)*100.0;
height2 = (mar/MAX_POSSIBLE_SALES)*100.0;


//drawing rectangles changing the color
obj_no = drawRect(200, 250, 50, height);
setColor(obj_no, 0, 255, 0);
drawRect(325, 250, 50, height1);
setColor(obj_no, 0, 0, 255);
drawRect(475, 250, 50, height2);
setColor(obj_no, 255, 0, 0);

return 0;
}

NOW EVERYTHING IS WORKING PERFECT BUT THE BARS THEY SHOULD HAVE THE HEIGHT OF THE EQUATION AND BE DRAWN DEPENDING OF THE INPUT BUT IT IS NOT DOING ANYTHING IT IS ALWAYS 0 WHAT AM I DOING WRONG?
We don't know anything about drawRect. When I look at it, though, it appears (though I may be wrong) that it takes an x coordinate and a y coordinate. So, to me, it would make sense if you added the first y coordinate to the heights (250) before plugging the heights into your drawRect().

-Albatross
it is still not working i do not know how to do it i am trying everything if somebody know please
We need to know more about drawRect, it seems. Could you maybe show us graph1.h in [code] blocks? Click the button on the side that looks like <>.

-Albatross
Last edited on
Topic archived. No new replies allowed.