I need help with a code. I am new to C++ and need help with this code so I can better understand the language. I have been stuck on this code and any help would be great...
To start, I was given two .txt files to use for this code:
* GirlNames.txt - This file contains a list of the 200 most popular names given to girls born in the United States from 2000 to 2009.
* BoyNames.txt - This file contains a list of the 200 most popular names given to boys born in the United States from 2000 to 2009.
Write a program that reads the contents of the two files into two separate arrays or vectors. The user should be able to enter a boy's name, a girl's name, or both, and the application should display messages indicating whether the names were among the most popular.
What exactly do you need help with? Are you stuck on using files, arrays, vectors, or something else? It's easier for us to help when we you have a specific issue you need help with. Nonetheless, here is a simple example to help get you going and if you have specific issues please post them here.
ill post them in a sec. I am getting confused on the order to put everything in. I understand the basics of it, but our teacher is so fast and hard to reach and I'm in the middle of moving so I am trying to catch up and understand everything. I have also been having problems getting files to display using C++. even after using codes in my book it still wont work. not sure if its my comp. or program. I'm using Microsoft visual studios. I will post both files below.
input[pb-role]::-ms-clear{ display:none;
}Jacob
Michael
Joshua
Matthew
Daniel
Christopher
Andrew
Ethan
Joseph
William
Anthony
David
Alexander
Nicholas
Ryan
Tyler
James
John
Jonathan
Noah
Brandon
Christian
Dylan
Samuel
Benjamin
Zachary
Nathan
Logan
Justin
Gabriel
Jose
Austin
Kevin
Elijah
Caleb
Robert
Thomas
Jordan
Cameron
Jack
Hunter
Jackson
Angel
Isaiah
Evan
Isaac
Mason
Luke
Jason
Gavin
Jayden
Aaron
Connor
Aiden
Aidan
Kyle
Juan
Charles
Luis
Adam
Lucas
Brian
Eric
Adrian
Nathaniel
Sean
Alex
Carlos
Bryan
Ian
Owen
Jesus
Landon
Julian
Chase
Cole
Diego
Jeremiah
Steven
Sebastian
Xavier
Timothy
Carter
Wyatt
Brayden
Blake
Hayden
Devin
Cody
Richard
Seth
Dominic
Jaden
Antonio
Miguel
Liam
Patrick
Carson
Jesse
Tristan
Alejandro
Henry
Victor
Trevor
Bryce
Jake
Riley
Colin
Jared
Jeremy
Mark
Caden
Garrett
Parker
Marcus
Vincent
Kaleb
Kaden
Brady
Colton
Kenneth
Joel
Oscar
Josiah
Jorge
Cooper
Ashton
Tanner
Eduardo
Paul
Edward
Ivan
Preston
Maxwell
Alan
Levi
Stephen
Grant
Nicolas
Omar
Dakota
Alexis
George
Collin
Eli
Spencer
Gage
Max
Cristian
Ricardo
Derek
Micah
Brody
Francisco
Nolan
Ayden
Dalton
Shane
Peter
Damian
Jeffrey
Brendan
Travis
Fernando
Peyton
Conner
Andres
Javier
Giovanni
Shawn
Braden
Jonah
Cesar
Bradley
Emmanuel
Manuel
Edgar
Erik
Mario
Edwin
Johnathan
Devon
Erick
Wesley
Oliver
Trenton
Hector
Malachi
Jalen
Raymond
Gregory
Abraham
Elias
Leonardo
Sergio
Donovan
Colby
Marco
Bryson
Martin
everything from the third line in the last two posts are the two separate .txt files. Even when I use codes from the book with reading from a .txt file, it doesn't seem to work. not sure why. I also am struggling with the order that everything goes in, especially with the arrays and vectors, and also adding new functions to the code. Theres some that I get, and some that I'm confused about. Our teacher goes threw it so fast its hard to keep track or get one on one time with him.
I tried the code that Rabster posted and created a .txt file on my desktop with the same name, ExampleData.txt and it shows nothing. I copied and posted the lines that your txt file said it contained into that txt file and saved it, and even tried to put the whole location in the quotation marks where it displays the file, and it still does not show anything when I run it. not sure why it will not work.
I started over, so far this is what I got but I need to figure out how to put each text file in a separate array and then match the user input or user guess to one of the names in either array or text file...
//test for 7-17
# include <iostream>
# include <fstream>
# include <string>
# include <vector>
# include <iterator>
//Read the names to check if there is a match
cout << girlNames.at(20) << "\n";
cout << boyNames.at(12) << "\n";
//Close the files
inputFile.close();
inputFileTwo.close();
//Display whethere there is a match in names or not
cout << "The name you picked, " << userInput << " was found on the list of most popular names!" << endl;
now all I need it to do is match the entire name that the user enters, to either one of the boy or girl names in the lists.... The code above picks a name out with similar letters or something, I need some type of loop or something to finish this code off.... ive been at this all day reading my book and looking online.. if anyone could help it would be appreciated.
My final code. It seems to check to see if the name entered is on the girl list, then the boy list, and if its not on either list, it lets you know. Still gonna try to figure out how to tell if its on both lists... its due tomorrow so I may just turn it in how it is.
//Ch7 HW Program Challenge 17
# include <iostream>
# include <fstream>
# include <string>
# include <vector>
# include <iterator>
//Read the names to check if there is a match, then display the results
if (find(boyNames.begin(), boyNames.end(), userInput) != boyNames.end())
cout << "The name you chose, " << userInput << ", is among the most popular boy names.\n";
else
if (find(girlNames.begin(), girlNames.end(), userInput) != girlNames.end())
cout << "The name you chose, " << userInput << ", is among the most popular girls names.\n";
else
cout << "The name you chose, " << userInput << ", is not among either list of popular names.\n";
//Close the files
inputFile.close();
inputFileTwo.close();