You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello there! I suggest you to have a look at the following program. Run it, read its code, and see how you could replicate the same, "nice, readable" stdout output!
Also, please do not use numbers to ask users for navigating menus! You might want to make use of actual words, and check if they are equal to a string without caring about the case. Put the entire query into a function so you can repeat it if the user enters something wrong. Also, do not perform checks on the input in the same function that also gives the user these options! Use another function for it. That way, you will be able to repeat certain tasks easily.
You might want to make functions to, say, print lists, simple lines, et cetera, then use those throughout the program along with separate functions to check the user's input. This will make things easier! Using function pointers here will give you extra convenience.
Feel free to ask me for example code doing this stuff!
#include<iostream>
#include<thread>
#include<chrono>
#pragma region // Header definitions!
#defineORIGINAL_WRITING_DELAY50;
template <typename T>
voidprint(T);
voidsleep(long);
voidwrite(std::string);
#pragma endregion
namespaceSpeed {
// This `static` limits these variables to this// "translation unit" (`.h` and `.cpp` combination.)/* static */long LETTER, COMMA, FULLSTOP, EXCLAIM;
voidreset()
{
LETTER = ORIGINAL_WRITING_DELAY;
COMMA = 4 * LETTER;
FULLSTOP = 10 * LETTER;
EXCLAIM = 6 * LETTER;
}
voidsetDelay(constlong p_to)
{
LETTER = p_to;
COMMA = p_to * 4.0f;
FULLSTOP = p_to * 10.0f;
EXCLAIM = p_to * 6.0f;
}
}
intmain(constint p_argCount, charconst *p_arrArgValues[]) {
Speed::reset();
printf("Yo, I'm here simply waiting for you to press Enter.");
std::cin.ignore();
write("Hello, World!\a");
}
template <typename T>
voidprint(T p_toOutput) {
std::cout << p_toOutput << '\n';
}
voidsleep(constlong p_time) {
std::this_thread::sleep_for(std::chrono::milliseconds(p_time));
}
voidwrite(const std::string p_str) {
char c;
constunsignedint length = p_str.length();
for (unsignedint i = 0; i < length; i++) {
usingnamespacestd;
c = p_str.at(i);
cout << c;
cout.flush();
usingnamespaceSpeed;// Sleep for some time, based on the character encountered:switch (c) {
case',':
sleep(COMMA);
break;
case'.':
sleep(FULLSTOP);
break;
case'!':
sleep(EXCLAIM);
break;
default:
sleep(LETTER);
}
}
std::cout << '\n';
}
The text was updated successfully, but these errors were encountered:
In fact, check out this repository I built over the last ~20+ hours, just for you!
Have a look at Main.cpp and perhaps also Main.hpp. You'll get an idea on how code should be organized for such programs. Putting all kinds of printing and input checking into separate functions of their own is very helpful to organize the code into loops.
Also, the program uses an extremely simple algorithm I wrote to do some string matching magic. Check it out on your nearest GNU-Linux machine!
Thanks a lot for ur suggestion but ... uh I did not understood the code i mean i am not sooo much good at c++ :( . all this went above my head :( all that i know in c++ i have used it in this prj so i know only this much in c++
Hello there! I suggest you to have a look at the following program. Run it, read its code, and see how you could replicate the same, "nice, readable"
stdout
output!Also, please do not use numbers to ask users for navigating menus! You might want to make use of actual words, and check if they are equal to a string without caring about the case. Put the entire query into a function so you can repeat it if the user enters something wrong. Also, do not perform checks on the input in the same function that also gives the user these options! Use another function for it. That way, you will be able to repeat certain tasks easily.
You might want to make functions to, say, print lists, simple lines, et cetera, then use those throughout the program along with separate functions to check the user's input. This will make things easier! Using function pointers here will give you extra convenience.
Feel free to ask me for example code doing this stuff!
The text was updated successfully, but these errors were encountered: