generated from ugreg/ugreg
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Tasks
- Port the existing C++ code to Rust
- Document how to setup Rust and run the new code
#include <iostream>
#include <vector>
#include <string>
const std::string RED = "\033[91m";
const std::string YELLOW = "\033[93m";
const std::string BLUE = "\033[94m";
const std::string PINK = "\033[95m";
const std::string GREY = "\033[90m";
const std::string RESET = "\033[0m";
const std::string filledSquare = "\u25A0";
void drawColoredBar(int percentage, const std::string& color) {
const int maxBarWidth = 50;
int filledWidth = static_cast<int>((static_cast<double>(percentage) / 100) * maxBarWidth);
std::cout << color;
for (int i = 0; i < filledWidth; ++i) {
std::cout << filledSquare;
}
std::cout << GREY;
for (int i = filledWidth; i < maxBarWidth; ++i) {
std::cout << filledSquare;
}
std::cout << RESET << " (" << percentage << "%)" << std::endl;
}
int main() {
std::vector<int> percentages = {52, 48, 32, 64};
std::vector<std::string> colors = {RED, YELLOW, BLUE, PINK};
for (size_t i = 0; i < percentages.size(); ++i) {
drawColoredBar(percentages[i], colors[i]);
}
return 0;
}Acceptance criteria
The code must compile and it must produce the same output as seen here:
. Create a pull request to the main branch with the working code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels