1

I'm trying to write a program that calculates the score of a text file (Flesch) by counting the words, sentences, and syllables in a program and right now I'm having trouble having by bool functions be declared after a write code for each one. Here's what I got: </p>

#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;

int numSentences, numWords, numSyllables; //for alphabet A-Z, a-z....unexpected    unqualified0id before 'int'
int isalpha(char isWordStarting);
bool inSentence, inWord, inSyllable;//


inSyllable(char isSyllableStarting);{//error: expected constructor, destructor, or    type conversion before ; token....
if (numSyllables = 'a','e','i','o','u'){//error: unqualified id before '{' token => inSyllable function
return true;}
  inSyllable(char isSyllableEnding);{
else {
return false;
}

      inWord(char isWordStarting);{
if(numWords = isalpha(char isWordStarting)){
  return true;}
   inWord(char isWordEnding);{
  else {
return false;
   }

       inSentence(char isSentenceStarting);{
   if(numSentences = '.',';',':','!','?'){
   return true;
   }
   inSentence(char isSentenceEnding);{
   else{
   return false;
   }
 int main (int argc[1], char*argv[]) {
   char c;
   ifstream infile;
   infile.open(agrv[1]);
   while (not (infile.eof());{ //start of loop
          infile.get(c);
          cout.put(c);

          for(int numSentences=0; numSentences < argc; numSentences++) { //Sentences
          cout << numSentences << ": " << argv[numSentences] << endl;
          }

          for(int numWords=0; numWords < argc; numWords++){ //Words
          cout << numWords << ": " << argv[numWords] << endl;
          }

          for(int numSyllables=0; numSyllables < argc; numSyllables++) {//Syllalbles
          cout << numSyllables << ": " << argv[numSyllables] << endl;
          }
          }
          infile.close(); //close file
          return 0;
          }

Any ideas? I put annotations next to the lines I'm having problems with.

4

1 回答 1

3

删除第一个错误行上的分号:)

分号不是函数定义,而是使它成为一个尝试的函数调用,后跟没有意义的大括号 - 它使编译器感到困惑。

inSyllable(char isSyllableStarting);{ //This one here.

另请注意,它应该有一个返回类型。它正在寻找一个构造函数,因为您的函数定义没有。


更多错误:您在这里的错误不止于此。例如,如果你在错误位置很好地分隔当前代码,你会得到这样的混乱:

inSyllable(char isSyllableStarting);
{
    if (numSyllables = 'a','e', 'i', 'o', 'u'){
        return true;
    }
    inSyllable( char isSyllableEnding);
    {
        else{
            return false;
        }

所以,这里有一个问题列表:

  1. 在函数大括号打开之前,半冒号不应出现在顶行。
  2. 您的 if 后面是对您的函数的递归调用,而不是错误地进一步向下的 else 。
  3. 你的大括号没有加起来 - 这个函数永远不会从上面的代码结束。
于 2013-05-09T19:58:44.513 回答