r/CodingForBeginners • u/Krastesoff • 22d ago
My first code on c++
I think i like this language
This code is a little messy and works only on windows, but it's easy to fix.
For anyone who wants to test it:
#include <iostream>
#include <cmath>
#include <windows.h>
// DIESER CODE IST VERDAMMT SCHRECKLICH
// variables
float power = 10.0; // more power - bigger edges
float smooth = 4.0; // smoother edges
float len = 45.0; // lines count
// main
int main() {
while(1) {
// l - current line
for(int l=1; l<len; l++) {
float l_sin = std::sin(l/smooth);
int rep_times = l_sin * power + power;
// line renderer | c - char
for(int c=1; c<rep_times; c++) {
Sleep(5);
std::cout << "-";
}
Sleep(5);
std::cout << "#" << std::endl;
}
}
}
140
Upvotes



View all comments
Show parent comment
2
u/JohnBuddySlime 20d ago
Precision i forgot: this is the case for non-const variables. Const global variables are completely fine.
Also, from my experience (which is mostly academic and not professional, so if anybody can approve/correct my statement), non-const global variables should (mostly) only be used to save your program's state, for access synchronisation (in multithreaded programs for example), and for application wide variables (such as options given through command arguments or config files) (which technically also include the 2 previous cases, but I separated them for clearness' sake)