Array, What's Wrong



#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

int main ()
{
double totalmonthlyAllowance, TotalchoreHours, averageChoreType;

int highestIndex, lowestIndex ;

double monthlyAllowance[ 3 ] ;
double choreMinutes[ 3 ] ;
double choreType[ 3 ] ;
string childfirstName[ 3 ] ;


childfirstName[ 0 ] = "Rachel" ;
choreType[0] = 1.0 ;
choreMinutes[0] = 32 ;


childfirstName[ 1 ] = "Jill" ;
choreType[1] = 3.0 ;
choreMinutes[1] = 29 ;


childfirstName[ 2] = "Andrew" ;
choreType[2] = 4.0 ;
choreMinutes[2] = 27 ;




totalMonthlyAllowance = 0.0 ;

totalChoreMinutes = 0.0 ;

int index ;

cout << setiosflags(ios::fixed) << setprecision(2) ;

cout << " First name Minutes Allowance Monthly allowance \n\n" ;

for ( index = 0 ; index <= 2 ; index = index + 1 )
{
monthlyAllowance[ index ] = choreMinutes[index] * choreType[ index ];

totalMonthlyAllowance += choreMinutes[ index ] ;

totalChoreMinutes += choreMinutes[index] ;

cout << setw(12) << childFirstName[ index ] << setw(8) << choreMinutes[index] << setw(8) << choreType[ index ] << setw(10) << monthlyAllowance[ index ] <<"\n" ;

}

cout << "\n" ;


averageChoreType = totalMonthlyAllowance / totalChoreMinutes ;
averageChoreMinutes = totalChoreMinutes / 3 ;

cout << "\nThe allowance is " << averageChoreType << "\n\n" ;
cout << "\nThe average minutes worked " << averageChoreMinutes << "\n\n" ;


highestIndex = 0 ;

for ( index = 1 ; index <= 2 ; index = index + 1 )
{
if ( choreType[index] > choreType[ highestIndex ] )
{
highestIndex = index ;
}
}


cout << "\n" << childFirstName[ highestIndex ] << " accrued the most money " << choreType[ highestIndex ] << "\n\n" ;
cout << "\n" << childFirstName[ highestIndex ] << " did the most chores " << choreMinutes[ highestIndex ] << "\n\n" ;



lowestIndex = 0 ;

for ( index = 1 ; index <= 3 ; index = index + 1 )
{
if ( choreType[index] < choreType[ lowestIndex ] )
{
lowestIndex = index ;
}
else if ( choreMinutes[index] < choreMinutes[ lowestIndex ] )
{
lowestIndex = index ;
}
}

cout << "\n" << childFirstName[ lowestIndex ] << " accrued the least amount of money " << choreType[ lowestIndex ] << "\n\n" ;
cout << "\n" << childFirstName[ lowestIndex ] << " spent the least amount of time on chores " << choreMinutes[lowestIndex] << "\n\n" ;




double tempChoreType ;
double tempChoreMinutes ;
string tempName ;

int pass, itemsToProcess = 3 ;

for ( pass = 0 ; pass < 3 ; pass = pass + 1 )
{
for ( index = 1 ; index < itemsToProcess ; index = index + 1 )
{
if ( choreType[index] < choreType[index - 1] )
else if ( choreMinutes[index] < choreMinutes[index - 1] )
{

tempChoreType = choreType[index - 1] ;
choreType[index - 1] = choreType[index] ;
choreType[index] = tempChoreType ;


tempChoreMinutes = choreMinutes[ index - 1 ] ;
choreMinutes[index - 1] = choreMinutes[index] ;
choreMinutes[index] = tempChoreMinutes ;


tempName = childFirstName[ index - 1 ] ;
childFirstName[index - 1] = childFirstName[index] ;
childFirstName[index] = tempName ;
}
}

itemsToProcess = itemsToProcess - 1 ;

}



cout << "display all chores in sorted order\n\n" ;

for ( index = 0 ; index <= 2 ; index = index + 1 )
{
cout << childFirstName[ index ] << " choir amount" << choreType[ index ] << "\n" ;
cout << childFirstName[ index ] << " minutes labored " << choreMinutes[index] << "\n" ;
}

cout << "\n" ;

return 0;

}




Why do I keep getting undeclared indentifier?
These are the errors I keep getting:
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(41) : error C2065: 'totalMonthlyAllowance' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(43) : error C2065: 'totalChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(55) : error C2065: 'totalMonthlyAllowance' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(57) : error C2065: 'totalChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(59) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(66) : error C2065: 'totalMonthlyAllowance' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(66) : error C2065: 'totalChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(67) : error C2065: 'averageChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(67) : error C2065: 'totalChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(70) : error C2065: 'averageChoreMinutes' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(84) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(85) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(103) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(104) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(120) : error C2181: illegal else without matching if
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(133) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(134) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(134) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(135) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(149) : error C2065: 'childFirstName' : undeclared identifier
1>c:\users\documents\c++\function not good\function not good\function not good.cpp(150) : error C2065: 'childFirstName' : undeclared identifier
Last edited on
I can tell you: The way you are asking is wrong ;)

http://www.cplusplus.com/forum/articles/1295/

Only people with to much time will take your code, put it on their computer and try to compile it and so on.
Please tell what you wonna reach und which errors or false results you get with this code.
Also write the code into source code tags with indents. So it's much easier for us to read and to understand.

Edit: Ah I see, it's the second time I told you ( http://www.cplusplus.com/forum/general/16968/ ). So I think this time you won't have so much luck like there ;)
Last edited on
Yeah Sorry, I accidently sent it before I put the errors in. Thank you for your comments last night that you left on my program, it helped me to understand a great deal!
Seems not to be an error directly inside the code.
Maybe someone can give you an answer who knows more about error C2065
Well they're all telling you that the variable you are referencing is not declared. In some cases you have
variable names misspelled, in some cases you have capitalization mismatches, and in other cases no
variable with a name close to the one you are trying to use has been declared.
Topic archived. No new replies allowed.