What's wrong with this code?

Pages: 12
Hi. Thanks for this. I think I understand it, and it makes me wonder why the tutors who tried to help never suggested it. I typed in the code you gave, but I'm now getting compile errors that I don't understand. Any idea what these mean?
/tmp/tioFsUkq3O/p09.cpp:29:32: error: declaration of story as multidimensional array must have bounds for all dimensions except the first
void askQuestions(char story[][])
^
/tmp/tioFsUkq3O/p09.cpp: In function void askQuestions(...):
/tmp/tioFsUkq3O/p09.cpp:31:20: error: story was not declared in this scope
for (int i = 0; story[i][0] != '\0' && i < 256; ++i)
^

Error compiling /tmp/tioFsUkq3O/p09.cpp.
[living4god1991@LinuxLab10 ~]$ testBed cs124/project09 p09.cpp
/tmp/F0C5uVnJNB/p09.cpp: In function void askQuestions(char*):
/tmp/F0C5uVnJNB/p09.cpp:31:30: error: invalid types char[int] for array subscript
for (int i = 0; story[i][0] != '\0' && i < 256; ++i)
^
/tmp/F0C5uVnJNB/p09.cpp:33:21: error: invalid types char[int] for array subscript
if (story[i][0] != '<' || !isalpha(story[i][1]))
^
/tmp/F0C5uVnJNB/p09.cpp:33:52: error: invalid types char[int] for array subscript
if (story[i][0] != '<' || !isalpha(story[i][1]))
^
/tmp/F0C5uVnJNB/p09.cpp:36:17: error: invalid types char[int] for array subscript
story[i][1] = toupper(story[i][1]);
^
/tmp/F0C5uVnJNB/p09.cpp:36:39: error: invalid types char[int] for array subscript
story[i][1] = toupper(story[i][1]);
^
/tmp/F0C5uVnJNB/p09.cpp:37:25: error: invalid types char[int] for array subscript
cout << story[i][1];
^
/tmp/F0C5uVnJNB/p09.cpp:38:43: error: invalid types char[int] for array subscript
for (int iStory = 1; story[i][iStory] == '>'; iStory++)
^
/tmp/F0C5uVnJNB/p09.cpp:40:29: error: invalid types char[int] for array subscript
if (story[i][iStory] == '_')
^
/tmp/F0C5uVnJNB/p09.cpp:44:28: error: invalid types char[int] for array subscript
story[i][iStory] = tolower(story[i][iStory]);
^
/tmp/F0C5uVnJNB/p09.cpp:44:55: error: invalid types char[int] for array subscript
story[i][iStory] = tolower(story[i][iStory]);
^
/tmp/F0C5uVnJNB/p09.cpp:45:36: error: invalid types char[int] for array subscript
cout << story[i][iStory];
^

Error compiling /tmp/F0C5uVnJNB/p09.cpp.
I have it fixed and now it should compile without errors. Also I have fitted the representation of the interface at the console, so I hope with this will you let pass the test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
 
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;

void getFilename(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;
}

/* AskQuestions() will iterate over a two-dimensional array.
   The first dimension represents the words and the 2nd
   dimension represents the characters of a word.
   After the last word the array needs an 'end' mark, it should be the '\0' character.
*/ 
void askQuestions(char story[][33])
{
    // iterates over each word in 'story'
    for (int i=0; story[i][0] != '\0' && i<256; ++i)
    {
        if (story[i][0] != '<' || !isalpha(story[i][1]))
           continue;   // Processes immediately the next loop turn.
           
        cout << "\t";
        story[i][1] = toupper(story[i][1]);
        for (int iStory = 1; story[i][iStory] == '>'; iStory++)
        {
            if (story[i][iStory] == '_')
                cout << " ";
            else
            {
                story[i][iStory] = tolower(story[i][iStory]);
                cout << story[i][iStory];
            }
        }
        
        // Saving the grammar requestion word in a new array,
        // and cutting cutting '<' and '>' away. 
        char word[33];  // Holds the grammar question word.
        int k = 1;  // For indexing column
        for (; story[i][k+1] != '\0'; ++k)
        {
            word[k-1] = story[i][k];
        }
        word[k-1] = '\0'; // Terminates the c-string
       
        cout << word << ":\n";
        cin >> story[i];
    }
    cout << "\nThank you for playing.\n";
}

int readFile(char story[][33], char fileName[])
{
   ifstream fin(fileName);
   if (fin.fail())
   {
      cout << "Error reading file " << fileName << ".\n";
      return 0;
   }
   int numWords = 0;
   while (fin >> story[numWords])
   {
      numWords++;
   }
   if (numWords > 256)
   {
      cout << "Error reading file " << fileName 
         << ". It has more than 256 words.";
      return 0;
   }
   fin.close();
   
   askQuestions( story );
   return numWords;
}

/**********************************************************************
*    The main function tells a program where to start.
***********************************************************************/
int main()
{
   char story[256][33];
   char fileName[256];
   getFilename(fileName);
   int wordCount = readFile(story, fileName);
   return 0;
}
Last edited on
This program suffers from some bugs and errors that must be silved. If you're having problems detecting those and the vulnerabilities, there are programs that might help, as checkmarx but my recommendation is to work hard on detecting bugs as you code. In order to save your time.
Good luck.
I managed to pass the first test with your code almost exactly, although I had to replace the \n at the end of word: with a space and remove the \n from before where it thanks the user for playing to do it. I'm still getting errors in test 2 though.
Starting Test 2

This second test has 13 prompts. The file is:
I feel like yelling <{> <web_site_name> <}> every time I <verb> the <#>
Internet . So many <plural_noun> to look for , so many <plural_noun>
to find . <#> <#> My mother asked me , <{> <proper_noun> , what is so
<adjective> about <#> the Web ? <}> <{> Well , <}> I said , <{> just
the other day I did a search for <noun> <#> by entering <[> <noun>
<boolean_operator> <noun> <]> in a search <#> engine . And it returned
<favorite_website> and <another_website> . It's <#> just so <adjective>
! <}> <#> <#> And then she knew what I meant . I felt so happy ! <#>

> Please enter the filename of the Mad Lib: /home/cs124/projects/madLibWeb.txt
> \tWeb_site_name:
Exp: Web site name:
Automobile Magazine.com
> \tVerb: \tPlural_noun:
Exp: Verb:
drive
> \tPlural_noun:
Exp: Plural noun:
cars
> \tProper_noun:
Exp: Plural noun:
motorcycles
> \tAdjective:
Exp: Proper noun:
New York
> \tNoun: \tNoun:
Exp: Adjective:
red
> \tBoolean_operator:
Exp: Noun:
Porsche
> Noun: BMW
> \tFavorite_website:
Exp: Boolean operator:
xor
> \tAnother_website:
Exp: Noun:
Ferrari
> \tAdjective:
Exp: Favorite website:
Car and Driver
> Thank you for playing.\n
Exp: Another website:
Ferrari.it
Okay, I'll try posting this again. For some reason, the website thinks I'm trying to post a duplicate post. I managed to pass test 1 with your code, although I had to modify a few things to do it. I replaced the \n at the end of word: with a space and got rid of the \n before where it thanks the user for playing. I'm still getting errors in test 2 though:
Starting Test 2

This second test has 13 prompts. The file is:
I feel like yelling <{> <web_site_name> <}> every time I <verb> the <#>
Internet . So many <plural_noun> to look for , so many <plural_noun>
to find . <#> <#> My mother asked me , <{> <proper_noun> , what is so
<adjective> about <#> the Web ? <}> <{> Well , <}> I said , <{> just
the other day I did a search for <noun> <#> by entering <[> <noun>
<boolean_operator> <noun> <]> in a search <#> engine . And it returned
<favorite_website> and <another_website> . It's <#> just so <adjective>
! <}> <#> <#> And then she knew what I meant . I felt so happy ! <#>

> Please enter the filename of the Mad Lib: /home/cs124/projects/madLibWeb.txt
> \tWeb_site_name:
Exp: Web site name:
Automobile Magazine.com
> \tVerb: \tPlural_noun:
Exp: Verb:
drive
> \tPlural_noun:
Exp: Plural noun:
cars
> \tProper_noun:
Exp: Plural noun:
motorcycles
> \tAdjective:
Exp: Proper noun:
New York
> \tNoun: \tNoun:
Exp: Adjective:
red
> \tBoolean_operator:
Exp: Noun:
Porsche
> Noun: BMW
> \tFavorite_website:
Exp: Boolean operator:
xor
> \tAnother_website:
Exp: Noun:
Ferrari
> \tAdjective:
Exp: Favorite website:
Car and Driver
> Thank you for playing.\n
Exp: Another website:
Ferrari.it
There was an error at line 29 ('==' instead of '!='). Therefore the loop was never entered. Also, in the old code it was not able reading-in more than a sigle word in a line. This I've fixed now. And then I made several small changes for that the original word will first then changed, if the new word will read in.

Here the output:

Please enter the filename of the Mad Lib: madLibWeb.txt
Web site name: Automobile Magazine.com
Verb: drive
Plural noun: cars
Plural noun: motorcycles
Proper noun: New York
Adjective: red
Noun: Porsche
Noun: BMW
Boolean operator: xor
Noun: Ferrari
Favorite website: Car and Driver
Another website: Ferrari.it
Adjective: yellow

Thank you for playing.


My code for 'askQuestions()'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void askQuestions(char story[][33])
{
    // iterates over each word in 'story'
    for (int i=0; story[i][0] != '\0' && i<256; ++i)
    {
        if (story[i][0] != '<' || !isalpha(story[i][1]))
           continue;   // Processes immediately the next loop turn.
           
        // We don't change the original text anymore.
        // Inststead we change the text at the output.
        cout << static_cast<char>(toupper(story[i][1]));
        
        for (int iStory = 2; story[i][iStory] != '>'; iStory++)
        {
            if (story[i][iStory] == '_')
            {
                cout << ' ';
            }
            else
            {
                cout << static_cast<char>(tolower(story[i][iStory]));
            }
        }
         
        cout << ": ";
        
        // Reads a whole line rather than a single word
        getchar();
        char ch = '\0';
        int k;
        for (k = 0; ch!='\n' && k<33; ++ k)
        {
            ch = getchar();
            story[i][k] = ch;
        }
        story[i][k] = '\0'; // terminates the c-string;
        
        // cerr << " debug:" << story[i]; // debug
        
    }
    cout << "\nThank you for playing.\n";
}
Why are you using getchar()? Mixing C++ streams and C-stdio functions is really not a very good practice. I'd recommend sticking with C++ streams, either cin.get() if you want to stick with getting the input character by character, or cin.getline() if you want to get an entire line from the user.

By the way you have several possible buffer overflow errors in your code. Take this for example:

for (int i=0; story[i][0] != '\0' && i<256; ++i)

Since you check for the "size" after you try to access the variable you could be trying to access story[] out of bounds. You should always check the "size" first, then check the character.

for (int i = 0; i < 256 && story[i][0] != '\0'; ++i)

And don't forget you should always be checking the "size" since you're using horrible C-strings instead of the better std::string.



Well, I'm aware of that C-like coding style at C++-code is a bunch of shit. And I'm not well practiced at this coding approach. If the prof would not restrict most of the basic C++ facilities, helping would much easier for me. I wonder why Living4God's prof is teaching C-technique at his/her students. I think, it's much harder becoming a good C++ coder when he/she at beginning interiorizes C-style techniques.
I tried the revised code for askQuestions and got a timeout during the tests:
Starting Test 1

This first test is trivial, reading the following file:
My pet cat is very <{> <adjective> . <}> <#> So is my dog . <#>
There is one prompt: "adjective" which needs to turn to "\tAdjective: "

> Please enter the filename of the Mad Lib: /home/cs124/projects/madLibTrivial.txt
Timed out!
Then there must be an error at 'getFiilename().

Here I have all of my program code, which it compiles and runs without errors. I have included jlb's suggestions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <fstream>
#include <cctype>
#include <cstring>
using namespace std;

void getFilename(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;
}

/* AskQuestions() will iterate over a two-dimensional array.
   The first dimension represents the words and the 2nd
   dimension represents the characters of a word.
   After the last word the array needs an 'end' mark, 
   it should be the '\0' character.
*/ 
void askQuestions(char story[][33])
{
    // iterates over each word in 'story'
    for (int i=0; i<256 && story[i][0]!='\0'; ++i)
    {
        if (story[i][0] != '<' || !isalpha(story[i][1]))
           continue;   // Processes immediately the next loop turn.
           
        // We don't change the original text anymore.
        // Inststead we change the text at the output.
        cout << static_cast<char>(toupper(story[i][1]));
        
        for (int iStory = 2; story[i][iStory] != '>'; iStory++)
        {
            if (story[i][iStory] == '_')
            {
                cout << ' ';
            }
            else
            {
                cout << static_cast<char>(tolower(story[i][iStory]));
            }
        }
         
        cout << ": ";
        
        // Reads a whole line rather than a single word
        cin.get();  // consumes the last '\n' character
        char ch = '\0';
        int k;
        for (k = 0; k<33 && ch!='\n'; ++ k)
        {
            cin.get(ch);    // reads a single char from standard input
            story[i][k] = ch;
        }
        story[i][k] = '\0'; // terminates the c-string;
        
        // cerr << " debug:" << story[i]; // debug
        
    }
    cout << "\nThank you for playing.\n";
}

int readFile(char story[][33], char fileName[])
{
   ifstream fin(fileName);
   if (fin.fail())
   {
      cout << "Error reading file " << fileName << ".\n";
      return 0;
   }
   int numWords = 0;
   while (fin >> story[numWords])
   {
      numWords++;
   }
   if (numWords > 256)
   {
      cout << "Error reading file " << fileName 
         << ". It has more than 256 words.";
      return 0;
   }
   fin.close();
   
   askQuestions( story );
   return numWords;
}

/**********************************************************************
*    The main function tells a program where to start.
***********************************************************************/
int main()
{
   char story[256][33];
   char fileName[256];
   getFilename(fileName);
   int wordCount = readFile(story, fileName);
   return 0;
}

Could you check whether its compiling and running correctly at your machine?

Here you could check if my textfiles are correct:

madLibTrivial.txt:
My pet cat is very <{> <adjective> . <}> <#> So is my dog . <#>

madLibWeb.txt:
I feel like yelling <{> <web_site_name> <}> every time I <verb> the <#>
Internet . So many <plural_noun> to look for , so many <plural_noun>
to find . <#> <#> My mother asked me , <{> <proper_noun> , what is so
<adjective> about <#> the Web ? <}> <{> Well , <}> I said , <{> just
the other day I did a search for <noun> <#> by entering <[> <noun>
<boolean_operator> <noun> <]> in a search <#> engine . And it returned
<favorite_website> and <another_website> . It's <#> just so <adjective>
! <}> <#> <#> And then she knew what I meant . I felt so happy ! <#>
Last edited on
I have included jlb's suggestions.

No, not really.

1
2
3
4
5
6
   while (fin >> story[numWords])
   {
      numWords++;
   }
   if (numWords > 256)
   {

Here you're checking numWords too late. If numWords, where checked, is greater than 256 it's too late, you've already overflowed the array.

1
2
        for (int iStory = 2; story[i][iStory] != '>'; iStory++)
        {

Where are you checking to insure iStory doesn't exceed the size of the array?

By the way what will happen if '>' is not contained in the "word"

Why are you starting with the third character in the array?

1
2
3
4
void getFilename(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;

Never use a function that will try to retrieve a C-string that doesn't limit the number of characters it will try to retrieve. The extraction operator>> can be limited by using the setw() manipulator before the call: cin >> setw(SIZE_OF_THE_ARRAY) >> fileName;. However the extraction operator>> is probably not the best choice for this operation, since filenames can contain whitespace characters in most modern operating systems, I would suggest getline() instead and you should be passing the SIZE_OF_THE_ARRAY into this function along with the array.

You should also consider creating named constants for the sizes of the various arrays, and you should be passing these sizes into your various functions as well.

Also are you sure it is safe to assume that one of the special "words" will be in the input? Just because your "simple" input tests are using some of these special "words" ("<{>", "<}>, <#>, etc") it may be possible that these "words" would not be in every "test" of your code.



I had to turn the assignment in since it was getting late, but I got feedback from my professor, and corrected the problems with it. Here's what it was supposed to look like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***********************************************************************
* Program:
*    Project 09, Mad Lib Program
*    Sister Unsicker, CS124
* Author:
*    Lanie Molinar
* Summary: 
*    This program is the second part of the Mad Lib project. It reads the Mad 
*    Lib from a file, making sure it's the right size, and prompts the user 
*    for words or phrases to fill in the needed text.
*
*    Estimated:  6.0 hrs   
*    Actual:     20.0 hrs
*      I could never get it to work, even though I followed the pseudocode and
*      got tutoring twice.
************************************************************************/

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

/***********************************************************************
* This function gets the file name from the user and passes it to the other 
* functions.
***********************************************************************/
void getFilename(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;
}

/***********************************************************************
*This function turns the prompts in the file into questions and asks the user
* for the information.
***********************************************************************/
void askQuestions(char story[])
{
   if (story[0] != '<' || !isalpha(story[1]))
      return;
   else if (story[0] == '<' && isalpha(story[1]))
   {
      cout << "\t";
      story[1] = toupper(story[1]);
      cout << story[1];
      for (int iStory = 1; story[iStory] == '>'; iStory++)
      {
         if (story[iStory] == '_')
            cout << " ";
         else
         {
            story[iStory] = tolower(story[iStory]);
            cout << story[iStory];
         }
      }
      cout << ": ";
      cin >> story;
   }
   cout << "\nThank you for playing.\n";
}

/***********************************************************************
* This function reads the Mad Lib file and passes information to the 
* askQuestions function.
***********************************************************************/
int readFile(char story[][33], char fileName[])
{
   ifstream fin(fileName);
   if (fin.fail())
   {
      cout << "Error reading file " << fileName << ".\n";
      return 0;
   }
   int numWords = 0;
   while (fin >> story[numWords])
   {
      askQuestions(story[numWords]);
      numWords++;
   }
   if (numWords > 256)
   {
      cout << "Error reading file " << fileName 
         << ". It has more than 256 words.";
      return 0;
   }
   fin.close();
   return numWords;
}

/**********************************************************************
*    The main function calls the getFilename and readFile functions.
***********************************************************************/
int main()
{
   char story[256][33];
   char fileName[256];
   getFilename(fileName);
   int wordCount = readFile(story, fileName);
   return 0;
}
Now, I'm working on the next part of the project, and for some reason, my playAgain function and the while loop in main are not working. This part is supposed to actually display the story and ask if the user wants to play again. Can you take a look?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/***********************************************************************
* Program:
*    Project 10, Mad Lib Program
*    Sister Unsicker, CS124
* Author:
*    Lanie Molinar
* Summary: 
*    This program is the final part of the Mad Lib project. It reads the Mad 
*    Lib from a file, making sure it's the right size, and prompts the user 
*    for words or phrases to fill in the needed text. It then displays the 
*    completed story.
*
*    Estimated:  10.0 hrs   
*    Actual:     20.0 hrs
*      I could never get it to work, even though I followed the pseudocode and
*      got tutoring twice.
************************************************************************/

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

/***********************************************************************
* This function gets the file name from the user and passes it to the other 
* functions.
***********************************************************************/
void getFilename(char fileName[])
{
   cout << "Please enter the filename of the Mad Lib: ";
   cin >> fileName;
   cin.ignore();
}

/***********************************************************************
*This function turns the prompts in the file into questions and asks the user
* for the information.
***********************************************************************/
void askQuestions(char story[])
{
   if (story[0] != '<' || !isalpha(story[1]))
      return;
   else
   {
      story[1] = toupper(story[1]);
      cout << "\t" << story[1];
      for (int iStory = 2; story[iStory] != '>'; iStory++)
      {
         if (story[iStory] == '_')
            cout << " ";
         else
         {
            story[iStory] = tolower(story[iStory]);
            cout << story[iStory];
         }
      }
      cout << ": ";
      cin.getline(story, 256);
   }
}

/***********************************************************************
* This function reads the Mad Lib file and passes information to the 
* askQuestions function.
***********************************************************************/
int readFile(char story[][33], char fileName[])
{
   ifstream fin(fileName);
   if (fin.fail())
   {
      cout << "Error reading file " << fileName << ".\n";
      return 0;
   }
   int numWords = 0;
   while (fin >> story[numWords])
   {
      askQuestions(story[numWords]);
      numWords++;
   }
   if (numWords > 256)
   {
      cout << "Error reading file " << fileName 
         << ". It has more than 256 words.";
      return 0;
   }
   fin.close();
   return numWords;
}

void displayStory(int wordCount, const char STORY[][33])
{
   for (int numWords = 0; numWords < wordCount; numWords++)
   {
      for (int iStory = 0; iStory < strlen(STORY[numWords]); iStory++)
      {
         char character = STORY[numWords][iStory];
         if (character != '<' && character != '>' && !isalpha(character))
         {
            if (ispunct(character))
               cout << character;
            switch (character)
            {
               case '#':
                  cout << endl;
                  break;
               case '{':
                  cout << " \"";
                  break;
               case '}':
                  cout << "\"";
                  break;
               case '[':
                  cout << " '";
                  break;
               case ']':
                  cout << "'";
            }
         }
         else if (isalpha(character))
         {
            for (int numWords = 0; numWords = wordCount; numWords++)
               cout << " " << STORY[numWords];
         }
      }
   }
}

char playAgain()
{
   char continue;
   do
   {
      cout << "Do you want to play again (y/n)? ";"
      cin >> continue;
   }
   while (continue != 'y' && continue != 'Y' && continue != 'n' && 
      continue != 'N')
   return continue;
}

/**********************************************************************
*    The main function calls the getFilename and readFile functions.
***********************************************************************/
int main()
{
   char story[256][33];
   char fileName[256];
   char continue = playAgain();
   while (continue != 'n' && continue != 'N')
   {
      getFilename(fileName);
      int wordCount = readFile(story, fileName);
      displayStory(wordCount, STORY);
   }
   cout << "\nThank you for playing.\n";
   return 0;
} 

I'm getting these errors:
p10.cpp:129:21: error: expected , or ... before continue
char playAgain(char continue)
^
p10.cpp: In function char playAgain(char):
p10.cpp:132:11: error: expected primary-expression before continue
cin >> continue;
^
p10.cpp:132:11: error: expected ; before continue
p10.cpp:133:11: error: expected primary-expression before continue
while (continue != 'y' || continue != 'n' || continue != 'Y' ||
^
p10.cpp:133:11: error: expected ) before continue
p10.cpp:133:20: error: expected ; before != token
while (continue != 'y' || continue != 'n' || continue != 'Y' ||
^
p10.cpp:133:20: error: expected primary-expression before != token
p10.cpp:133:30: error: expected primary-expression before continue
while (continue != 'y' || continue != 'n' || continue != 'Y' ||
^
p10.cpp:133:30: error: expected ; before continue
p10.cpp:140:11: error: expected primary-expression before continue
return continue;
^
p10.cpp:140:11: error: expected ; before continue
p10.cpp:140:11: error: continue statement not within a loop
p10.cpp: In function int main():
p10.cpp:150:9: error: expected unqualified-id before continue
char continue = playAgain(continue);
^
p10.cpp:151:11: error: expected primary-expression before continue
while (continue != 'n' && continue != 'N')
^
p10.cpp:151:11: error: expected ) before continue
p10.cpp:151:20: error: expected ; before != token
while (continue != 'n' && continue != 'N')
^
p10.cpp:151:20: error: expected primary-expression before != token
p10.cpp:151:30: error: expected primary-expression before continue
while (continue != 'n' && continue != 'N')
^
p10.cpp:151:30: error: expected ; before continue
Topic archived. No new replies allowed.
Pages: 12