Input and Output Project

C++ File I/O Project

I need help to write a program that allows a user to use
the keyboard to input the first and last names
of 40 friends, up to 50 characters each. I need
to display the names 15 at a time, pausing to let
the user press a key before the list continues.

I got the names but the code is something different, could someone help me get started?

Oh my god this was a pain, also this was not my idea it is just required my my teacher

1. Noah Anderson

2. Liam Bardot

3. Mason Becker

4. Jacob Beckett

5. William Cohen

6. Ethan Coleman

7. Michael Copeland

8. Alexander Davis

9. James Delaney

10. Daniel Willis

11. Nick Devlin

12. Benjamin Dixon

13. Logan Gibbs

14. Aiden Duncan

15. Jayden Ellis

16. Matthew Griffin

17. Jackson Finley

18. David Hendrix

19. Lucas Hutton

20. Joseph Hepburn

21. Idiana Jones

22. Andrew Lennon

23. Samuel Adams

24. Gabriel Lincoln

25. Joshua Miller

26. John Monroe

27. Carter Sutton

28. Luke Sullivan

29. Alen Walker

30. Christopher Columbus

31. Isaac Newton

32. Oliver Twist

33. Henry Smith

34. Sebastian Jennings

35. Ronald McDonald

36. Owen Kennedy

37. Ryan Penn

38. Nathan Langley

39. Wade Wilson

40. Hunter Stone
Last edited on
Well. This is a bizzare project. It's extremely simple, but you have to enter 40 first and last names? Christ...

Let's say all names are entered and saved in a std::string array.

You need 2 things. A variable of type integer that counts to 15. And a for-loop that runs 40 times. Inside the loop you have an if statement which checks if counter == 15. If it is, then let the user press a thing and restart the counter back to 0.

So I could start it like this? Also I am like worst than a beginner. but when you said an integer that counts to 15 I am not sure how to do that would I have to declare a separate variable and then make a function?

I think I have to use #include <fstream> as well but just for the user to input and for me to extract the file.

and one more thing, sorry for asking so many questions, but would I need a cin of the names that the person could type in?

#include <iostream>

using namespace std;

int main()
{

///array with names
array Names [ 40 ] = {Names ------>};

///function checking if variable is 15 names
if counter == 15
{

}


return 0;
}

Im kinda confused now, and I think you are too. Because you mentioned the user has to input the 40 names, now you're saying you have to use <fstream> which would suggest the names should be in a file and you have to read it in using File I/O

but when you said an integer that counts to 15 I am not sure how to do that would I have to declare a separate variable and then make a function?


int counter = 0; After reading in a name, you add 1 to it by doing counter++;
Once it reaches 15, you do the stuff with it.
1
2
3
4
if counter == 15 you're missing the parenthesis, should be (counter == 15)
{
    // http://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm
} 
Last edited on
Sorry, I get really confused, I wasn't sure if i had to use <fstream> I got that mixed up with something else, but I do know that the user has to input the names and then I take that list and show it to them 15 names at a time and it pauses after 15 names and they press enter to continue the list.
I would suggest you start with 6 names, and pause after 2 names. I would also suggest to start with, instead of a user entering them, because that would take forever since you'll have to re-run the code plenty of times to fix errors and stuff, to just predefine them in an array.

std::string names[6] = {"Mike", "Bike", "Like", "Hike", "Sike", "Xike"};
Don't forget to #include <string>

Now basically use a for-loop that runs 6 times and use an if statement to check when counter is equal to 2.
Ok thank you for your help
Topic archived. No new replies allowed.