making a bar graph

Hi, I'm taking a computer science class and one of our assignments required me to make a bar graph using xcode and sfml. We had to input a file for the heights, but my heights aren't working. I've attached my code below. Please take a look at it! Thank you!!!!//
// Disclamer:
// ----------
//
// This code will work only if you selected window, graphics and audio.
//
// In order to load the resources like cute_image.png, you have to set up
// your target scheme :
//
// - Select "Edit Schemeā€¦" in the "Product" menu;
// - Check the box "use custom working directory";
// - Fill the text field with the folder path containing your resources;
// (e.g. your project folder)
// - Click OK.
//

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <fstream>

using namespace std;

int main(int argc, char const** argv)
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 800), "SFML window");


//create a file input stream
fstream inputFile("/Users/erinbell/Desktop/tmp/data5.txt");
// next create to variables to hold the
// data I want to read in
int width1;
int height1;
int width2;
int height2;
int width3;
int height3;
int width4;
int height4;
int width5;
int height5;

// read values from the file
inputFile >> width1;
inputFile >> height1;
inputFile >> width2;
inputFile >> height2;
inputFile >> width3;
inputFile >> height3;
inputFile >> width4;
inputFile >> height4;
inputFile >> width5;
inputFile >> height5;


// Create rectangle object
//sf::RectangleShape rec1(sf::Vector2f(20, 300));
//sf::RectangleShape rec2(sf::Vector2f(20, 150));
//sf::RectangleShape rec3(sf::Vector2f(20, 120));
//sf::RectangleShape rec4(sf::Vector2f(20, 450));
//sf::RectangleShape rec5(sf::Vector2f(20, 240));

sf::RectangleShape rec1(sf::Vector2f(width1, height1));
sf::RectangleShape rec2(sf::Vector2f(width2, height2));
sf::RectangleShape rec3(sf::Vector2f(width3, height3));
sf::RectangleShape rec4(sf::Vector2f(width4, height4));
sf::RectangleShape rec5(sf::Vector2f(width5, height5));

//Now move the rectangle to a different position
rec1.move(200, 700); // This moves the Rectangle over 200 pixels and down 700 pixels
rec2.move(300, 700); // This moves the Rectangle over 300 pixels and down 700 pixels
rec3.move(400, 700); // This moves the Rectangle over 400 pixels and down 700 pixels
rec4.move(500, 700); // This moves the Rectangle over 500 pixels and down 700 pixels
rec5.move(600, 700); // This moves the Rectangle over 600 pixels and down 700 pixels

// Set Rectangle to Green, Blue, Pink, Red
rec1.setFillColor(sf::Color(100,250,50));
rec2.setFillColor(sf::Color(10,20,100));
rec3.setFillColor(sf::Color(500,600,700));
rec4.setFillColor(sf::Color(200,300,50));
rec5.setFillColor(sf::Color(10,100,45));

//Draw in Graphic Window
window.clear();

//Now Draw My Rectangle
window.draw(rec1);
window.draw(rec2);
window.draw(rec3);
window.draw(rec4);
window.draw(rec5);


//Tell the Window to Display
window.display();

sf::sleep(sf::seconds(8));



return EXIT_SUCCESS;
}
Topic archived. No new replies allowed.