Trouble with inFile and do while loops and functions

I am having some trouble with my functions. Here is a list of my errors. I am at a loss and I could use some insight.

Z:\CS 150\Project2\SmithD_Prj2 v1.cpp||In function 'int main()':|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|59|error: a function-definition is not allowed here before '{' token|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|75|error: no matching function for call to 'getline(std::ifstream&, int&)'|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|75|note: candidates are:|
c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\basic_string.tcc|1070|note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)|
c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\basic_string.tcc|1070|note: template argument deduction/substitution failed:|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|75|note: mismatched types 'std::basic_string<_CharT, _Traits, _Alloc>' and 'int'|
c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\basic_string.h|2792|note: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)|
c:\mingw\bin\..\lib\gcc\mingw32\4.7.0\include\c++\bits\basic_string.h|2792|note: template argument deduction/substitution failed:|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|75|note: mismatched types 'std::basic_string<_CharT, _Traits, _Alloc>' and 'int'|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|87|error: variable or field 'userInfo' declared void|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|87|error: 'str' was not declared in this scope|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|87|error: 'userName' was not declared in this scope|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|87|error: expected primary-expression before 'int'|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp||In function 'void getNumber(int&)':|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|116|error: 'inFile' was not declared in this scope|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp||In function 'double calculateRatio(int&, int&, int&)':|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|139|error: declaration of 'double ratio' shadows a parameter|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp||In function 'void printResults(int, int, int, int&)':|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|150|error: declaration of 'int evenCount' shadows a parameter|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|151|error: declaration of 'int zeroCount' shadows a parameter|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|152|error: declaration of 'int oddCount' shadows a parameter|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|153|error: declaration of 'double ratio' shadows a parameter|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|166|error: 'inFile' does not name a type|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|168|error: expected unqualified-id before 'return'|
Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|169|error: expected declaration before '}' token|
||=== Build finished: 22 errors, 0 warnings ===|


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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
 /*==============================================
  Project 2
  Source file: Smith_D_Prj2
  Programmer : Debra Smith
  Date       : 10/16/13
  Lab        : 15749
  Description:  This program is designed to modify an existing
  program's functions based on input files versus user input.
  =============================================================*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

using namespace std;

//const int N = 20;         Don't need this

    //Function prototypes
void initialize(int& zeroCount, int& oddCount, int& evenCount, int& ratio);
void getNumber(int& num);
void classifyNumber(int num, int& zeroCount, int& oddCount,
                    int& evenCount);
void printResults(int zeroCount, int oddCount, int evenCount);
void userInfo (string userName, int& userCount);
void inputErr ();

int main ()
{
        //Variable declaration
    int counter = 0; //loop control variable
    int number = 0;  //variable to store the new number
    int zeros = 0;   //variable to store the number of zeros
    int odds = 0;    //variable to store the number of odd integers
    int evens = 0;   //variable to store the number of even integers
    double ratio = 0;  //variable to reflect the value found when the number of evens is divided by the number of odds.
    string userName =" ";
    string inputFile = " ";
    int userCount = 0;
    char replay = '\0';


    ifstream inFile;

    inFile.open("input.txt");

do
{

	cout << "Enter the name of the input file:  ";
	cin  >> userName;
	cout << endl;

}

while (replay != 'N');

void inputErr(string message ) {

    cout <<"\n\n\n*******************************************";
    cout <<"\nERROR!\tERROR!\tERROR\tERROR!\tERROR!\tERROR!\n";
    cout <<"\n\n\tInput File Not Found!\n\n";
    cout <<"     exiting with Error:  Debra-00934509";

}


    //initialize(zeros, odds, evens);                 //Step 1  Come back to this..  What's going on?

    for (counter = 1; counter <= 20; counter++)      //Step 3
    {
       // getNumber(number);                          //Step 3a   get number from input file
       //cout << number << " ";                                     get number from input file
        getline(inFile, number);
        inFile >> number;                      //Step 3b
        classifyNumber(number, zeros, odds, evens); //Step 3c
    }// end for loop

    cout << endl;

    printResults(zeros, odds, evens);               //Step 4

    return 0;
}

char readYesNo(){
     //Declare Variables
     char input = '\0';

     //User Prompt

     cout << "\n\nEnter y or Y to continue or any other key to exit.  ";
     cin  >> input;

     cin.ignore( 100, '\n' );

     //return input
     return input;
}	

void userInfo(str& userName, int& userCount) {

    inFile >> userName;
    inFile >> userCount;

    cout <<"/*=============================================================";
    cout <<"\nProgrammer : Debra Smith";
    cout <<"\nDate       : 10/16/13";
    cout <<"\nFile Name  : Smith_D_Prj2.cpp";
    cout <<"\n\nFile User Name: " ;
    inFile >> userName;
    cout << userName;
    cout <<"\n\nFile User Count: " ;
    inFile >> userCount;
    cout << userCount;

}  // end user info function

void initialize(int& zeroCount, int& oddCount, int& evenCount, int& ratio) {

    zeroCount = 0;
    oddCount = 0;
    evenCount = 0;
    ratio = 0;

} // end initialize function

void getNumber(int& num) {

    inFile >> num;

} // end get number function

void classifyNumber(int num, int& zeroCount, int& oddCount,
                    int& evenCount) {
    switch (num % 2)
    {
        case 0:
            evenCount++;
            if (num == 0)
                zeroCount++;
            break;
       case 1:
       case -1:
           oddCount++;
   } //end switch


} //end classifyNumber

double calculateRatio( int& evenCount, int& oddCount, int& ratio ){
     //Declare variables
     double ratio= 0;

     //Calculate the score
     ratio = (evenCount) / (oddCount );

     //return the calculated ratio
     return ratio;
} // end calculate ratio

void printResults(int zeroCount, int oddCount, int evenCount, int& ratio) {

    int evenCount = 0;
    int zeroCount = 0;
    int oddCount = 0;
    double ratio = 0;

    cout << "There are " << evenCount << " evens, "
         << "which includes " << zeroCount << " zeros"
         << endl;

    cout << "The number of odd numbers is: " << oddCount
         << endl;
    cout << fixed << showpoint << setprecision(6);
    cout << "The ratio of odd numbers/even numbers is:" << ratio;
    cout << endl;
} //end printResults

    inFile.close( );

     return 0;
}
//--------------------------------------------------------------

Fix the first error and usually lots of the others will disappear.

Z:\CS 150\Project2\Smith_D_Prj2 v1.cpp|59|error: a function-definition is not allowed here before


You define your functions inside main(). You cannot do this. Cut them and paste them after

1
2
3
     return 0;
}
//-------------------------------------------------------------- 
Topic archived. No new replies allowed.