Ok. I'm doing a test that I am sure to fail. I figured I should ask for help first.
This is the question:
"1. For each variable in the following C++ code, list the data type, the scope and the storage duration'
Code:
#include <iostream>
#include <string>
#include <cctype>
std::string result;
int parseInt(const std::string &s)
{
static std::string digits[] = {"cero", "uno", "dos", "tres", "cuatro",
"cinco", "seis", "siete", "ocho", "nueve"};
static int count = 0;
count++;
result = "";
for (unsigned int i = 0; i < s.length(); i++)
{
if( isdigit(s[0]) == 0 ) //not a digit
return -1;
result += digits[s.at(i) - '0'];
if(i < s.length() - 1)
result += ",";
}
return 0;
}
int main(int argc, char *argv[]) {
std::string n;
std::cout << "Please enter an integer or \"quit\""
" to finish (example: 897).\n";
std::cin >> n;
while (n != "quit")
{
if ( parseInt(n) != 0 )
std::cerr << n << " is NOT a valid integer\n";
else
std::cout << n << " == " << result << "\n";
std::cin >> n;
}
return 0;
}
2. The above code has a small mistake. It does not reject input like 987.8. Can you find and fix the mistake?"
Ok. Data types? Scope? Storage duration? If you guys could define what that means and what those look like, I'd be off to a much better start
For part 2, I'm not 100% sure...but...could you use the assert() thing?
Any tips would be appreciated. I'm not asking you to do it for me, so please don't accuse me of doing so.
Thank you for your valuble help.