0

Need some assistance with my written C++ code, it doesn't run now anymore!

I have written some C++ code of my own in 'Code Bits' to draw a triangle in the output screen, based off of user input. This code isn't public so here it is: #include <iostream> #include <string> using namespace std; // declare the variables that will be used int numOfSpaces, numOfSymbols, maxNumOfSymbols; const string SPACE = " "; char myChosenSymbol; void InputMaxNumberOfSymbols() { do { cout << "Enter the maximum number of symbols you want for the triangle (Must be odd): "; cin >> maxNumOfSymbols; } while (maxNumOfSymbols % 2 != 1); cout << endl; } void SetValues() { /* This function only accepts a single character for the symbol input The acceptable list of characters are those characters from the ASCII character list that can be displayed on the screen. */ cout << "Enter a single character of your choosing for the triangle: "; cin >> myChosenSymbol; cout << endl; InputMaxNumberOfSymbols(); numOfSpaces = (maxNumOfSymbols - 1) / 2; numOfSymbols = 1; /* The line below is used to prevent the top of the triangle appearing directly below the output string of this method. */ cout << endl; } void OutputSpaces() { for (int a = 1; a <= numOfSpaces; a++){ cout << SPACE; } } void OutputSymbols() { for (int b = 1; b <= numOfSymbols; b++){ cout << myChosenSymbol; } } void AdjustValuesForNextRow() { numOfSpaces -= 1; numOfSymbols += 2; } int main() { //Calling our written methods! SetValues(); do { OutputSpaces(); OutputSymbols(); AdjustValuesForNextRow(); cout << endl; //Shift the output feed to next line } while (numOfSymbols < maxNumOfSymbols); return 0; } Initially the code worked fine, but after changing the while condition in 'int main()' to '<=' causes timeout errors. So, I reverted the condition back to '<' and now the code never executes. Is this a caching error or something else? Please provide suggestions. Thanks!

8th Jul 2023, 8:19 AM
Faizan Ahmed
Faizan Ahmed - avatar
3 Réponses
+ 3
It works perfectly fine in my IDE and SoloLearn. What do you mean? By the way, please send us the link to your code directly, instead of pasting the code in the description! No matter whether the code is public or not, everyone can still see your code through links! For example, `private` codes are only accessible through links or if you are the author of that code.
8th Jul 2023, 9:22 AM
Dragon RB
Dragon RB - avatar
0
Dragon RB I was running on the code on PC. I accessed SoloLearn on my PC and executed the code there. This is the link: https://www.sololearn.com/compiler-playground/cHan7HQXun1i
8th Jul 2023, 11:45 AM
Faizan Ahmed
Faizan Ahmed - avatar
0
What I meant by timeout error is that instead of the triangle being displayed in the output, I saw 'Execution Timed Out!' every time after changing the while condition in main() to '<='. Even after reverting the condition back to '<' I still saw 'Execution Timed Out' in the output. Hence I thought it was either a caching error where the server believed I was still using the old code, or it could have been that the server may have been under load and refused to work for a while. Now when I test it, it works fine. By the way, thanks for the help @Dragon RB!
8th Jul 2023, 6:12 PM
Faizan Ahmed
Faizan Ahmed - avatar