This program is supposed to take a boy or girl name and output its popularoty rank.
The text file is laid out as
1. Jacob Emily
2. David Alyssa
...
...
I cant figure out what I am doing wrong. Some suggested:
else if(boyRank !=0 && girlsRank = 0)
You probably want an == there, not an =.
but then is reports : expected primary-expression before '=' token
Code:#include <iostream> #include <fstream> #include <cstring> #include <cstdlib> using namespace std; int main() { char boys[1000][20], girls[1000][20], targetName[20], found; int count = 0, boyRank, girlsRank, num; cout<<"Enter the first name that you would like to find the \n"; cout<<"popularity of from baby names in 2004.\n"; cout<<"Be sure to capitalize the first letter of the name"<<endl; cin >> targetName; ifstream in; in.open ("babynames2004.txt"); if (in.fail( )) { cout << "Input file opening failed.\n"; exit(1); } while(count < 1000 && in >> boys[count] >> girls[count]) { count++; } for (int i = 0; i < 1000; i++) { if(strcmp(targetName, boys[i])==0) { found = true; boyRank = i+1; } if(strcmp(targetName, girls[i])==0) { found=true; girlsRank = i+1; } if(boyRank !=0 && girlsRank !=0) { cout << targetName <<" is ranked "<< boyRank <<"among boys.\n"; cout << targetName <<" is ranked "<< girlsRank <<"among girls.\n"; } else if(boyRank !=0 && girlsRank = 0) { cout << targetName <<" is ranked "<< boyRank <<"among boys.\n"; cout << targetName <<" is not ranked among to 1000 girl names.\n"; } else if(boyRank = 0 && girlsRank != 0) { cout << targetName <<" is ranked "<< girlsRank <<"among girls.\n"; cout << targetName <<" is not ranked among to 1000 boy names.\n"; } } return 0; }



1Likes
LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.