# Simple problem that I can't comprehend

• 12-09-2004
phosphorousgobu
Simple problem that I can't comprehend
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.
• 12-09-2004
PJYelton
Ummmm... so many problems with this....

Second, the question says to list the data types, scope and storage, you ask us to define all of these things and point them out in the code, then say you aren't asking us to do it for you?? Thats exactly what you just asked so hell yeah I'm going to accuse you of asking us to do it for you!

Sorry, this is obviously an end of the semester test, if by now you don't know these simple programming concepts we aren't going to help you pretend to the teacher that you do.
• 12-09-2004
PJYelton
BAH xErath, what are you doing?? You are helping him cheat on a test??? :mad: :mad:
• 12-09-2004
xErath
Quote:

Originally Posted by phosphorousgobu
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.

1st I read, then I post. You should try the same thing to.