Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input is valid. A string will take pretty much anything you throw at it, so it will always accept it's new value (unlike int
for example). However, you usually do not want all input to be accepted. What should happen in case of an empty line for example? And how does your program respond to special characters like ▓
, ƒ
, ▄
and !!
(notice the latter is actually one character, not two !
).
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input is valid. A string will take pretty much anything you throw at it, so it will always accept it's new value (unlike int
for example). However, you usually do not want all input to be accepted. What should happen in case of an empty line for example? And how does your program respond to special characters like ▓
, ƒ
, ▄
and !!
(notice the latter is actually one character, not two !
).
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input is valid. A string will take pretty much anything you throw at it, so it will always accept it's new value (unlike int
for example). However, you usually do not want all input to be accepted. What should happen in case of an empty line for example? And how does your program respond to special characters like ▓
, ƒ
, ▄
and !!
(notice the latter is actually one character, not two !
).
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input really is positivevalid. A string will take pretty much anything you throw at it, so it will always accept it's new value (unlike int
for example). However, you usually do not want all input to be accepted. What should happen in case of an empty line for example? And how does your program respond to special characters like ▓
, ƒ
, ▄
and !!
(notice the latter is actually one character, not two !
).
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input really is positive.
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input is valid. A string will take pretty much anything you throw at it, so it will always accept it's new value (unlike int
for example). However, you usually do not want all input to be accepted. What should happen in case of an empty line for example? And how does your program respond to special characters like ▓
, ƒ
, ▄
and !!
(notice the latter is actually one character, not two !
).
You'll either want to validate or sanitize your input data (or both).
Comments
Code should be self commenting. Your comments are superfluous.
//Declare Variables.
string input;
int size;
Namespaces
using namespace std;
is considered bad practice. Short code is not a requirement in C++, clear code is preferred.
Return
return 0;
is a legacy from C. In C++, it's no longer required to write this manually. The compiler will take care of returning 'normal' if no errors where thrown or other returns (like -1
) are encountered.
Input validation
You expect the user to input a positive number at cin >> input;
. However, there is nothing in your program checking whether the input really is positive.
You'll either want to validate or sanitize your input data (or both).