Solved

C++ Error about parenthesis

Posted on 2006-11-03
2
279 Views
Last Modified: 2010-04-16
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;
      }
      return total;
}


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
0
Comment
Question by:xneo27
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 17868388
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++)
0
 
LVL 30

Expert Comment

by:callrs
ID: 17868455
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);

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question