This code compiles and executes as is.
However I wish to allow the user to select the color in the function.
Using either cin or scanf compiles but does not execute.
Help please?
Warren
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
void NameColor();
int rd, gr, bl;
int main()
{
int j, radius = 25;
// Create the main rendering window
sf::RenderWindow App(sf::VideoMode(1400, 900, 32), "Warren Graphics");
// Clear screen
App.Clear(sf::Color(128, 128, 128));
for(j = 1; j < 5; j++)
{
NameColor();
// Draw circle
App.Draw(sf::Shape::Circle(250,j*100+5,radius,sf::Color(rd,gr,bl)));
// Display window contents on screen
App.Display();
}
// Start game loop
while (App.IsOpened())
{
// Process events
sf::Event Event;
while (App.GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App.Close();
//Escape key exit
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
}
return EXIT_SUCCESS;
}
void NameColor()
{
int value;
// Get color from Random
value = sf::Randomizer::Random(1,6);
// Get color from key press
// scanf("%d",&value);
// cin >> value;
// Define color
if(value == 1)
{
rd = 0;
gr = 0;
bl = 255;
}
if(value == 2)
{
rd = 255;
gr = 0;
bl = 0;
}
if(value == 3)
{
rd = 255;
gr = 255;
bl = 255;
}
if(value == 4)
{
rd = 0;
gr = 255;
bl = 0;
}
if(value == 5)
{
rd = 255;
gr = 255;
bl = 0;
}
if(value == 6)
{
rd = 0;
gr = 0;
bl = 0;
}
}