We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

on
Medium Priority
297 Views
Heres my code:

//The convert function takes a string of numbers and returns its integer value.
int convert(string strNum)
{
char c;
const int Size = strNum.size();
int I;
int J;
int X;
int Y;
int total;
int tmpint1;
int tmpint2;
const int plusone = Size + 1;

for (I = 1, I < plusone, I++)
{
X = Size - I;
if (X > 0)
{
Y = 10;
for(J = 1, J < X, J++)
{
Y = Y * 10;
}
}
else Y = 1;
c = strNum.substr(I,I);
tmpint1 = c - '0';
tmpint2 = tmpint1 * Y;
total = total + tmpint2;
}
}

Heres the odd errors im getting:

sr1 \$ CC -o Program08 Program08.cpp
"Program08.cpp", line 170: Error: Unexpected ")" -- Check for matching parenthesis.
"Program08.cpp", line 171: Error: Use ";" to terminate statements.
"Program08.cpp", line 171: Error: Expected an expression.
"Program08.cpp", line 176: Error: Unexpected ")" -- Check for matching parenthesis.
"Program08.cpp", line 177: Error: Use ";" to terminate statements.
"Program08.cpp", line 177: Error: Expected an expression.
"Program08.cpp", line 182: Error: Cannot assign std::string  to char.
7 Error(s) detected.

Can anyone tell me why im getting these errors... If you need more code I can post it but I commented out this function and the errors disappeared
Comment
Watch Question

## View Solution Only

Awarded 2006
Top Expert 2006
Commented:
for (I = 1, I < plusone, I++)         |   for(J = 1, J < X, J++)
should be
for (I = 1; I < plusone; I++)        |    for(J = 1; J < X; J++)

Not the solution you were looking for? Getting a personalized solution is easy.

Awarded 2006
Top Expert 2006

Commented:
http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html    string class

That shows how to use substr. E.g.
string str("Hello Universe!");
string start = str.substr(0, 5);
string end = str.substr(5);

##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile