Solved

C++ Error about parenthesis

Posted on 2006-11-03
2
272 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now