hello, new to programming, doing an assignment where it is asking the user to enter names which are then written to a file. the range of names is 7-25. the program is to display to the user which name is first alphabetically and which is last.this is supposed to be accomplished without using arrays or functions because we haven't covered the material yet. we have covered loops though. i have no issues opening/writing to the file but i'm stumped as to what kind of algorithm i should use to rank the strings. any help is greatly appreciated
As I see things, if you are not allowed to use arrays, then you will need to invent the functionality of an array using lots of independent variables. That will make the task about a hundred times more difficult. I find it hard to believe this is really the task that has been set.
Actually I may be mistaken.
I was thinking in terms of sorting the entire set of data.
If all you need is the first and last alphabetically, then the job is reasonably straightforward.
Its very much analogous to finding the min and max of a list of numbers.
You just need two variables (strings) to hold the first and last.
Read the first data item, set both the first and last equal to that value.
Then read each item after that in turn, if it is earlier alphabetically than the first, replace the existing first with the current item. Similarly, if it is later alphabetically than the last, replace last with the current item.
should i use a getline
should the names be ranked before they are sent to the file
I don't quite see the meaning of "or" in that question.
The first part, getline is particularly suited when a single string may contain multiple words. If the string must definitely not contain multiple words, then getline may be unsuitable.
The second part, you should determine the first and last name alphabetically during the process which handles each name. Whether that is before or after sending it to the file doesn't matter.
lastly which kind of loop should i use
This may depend on how the end of the user input is to be determined. If there is a known quantity of data, then a for loop may suit. A while loop is more general-purpose and may be better. But what will be the condition which terminates the user input? Decide upon that and you can then decide how to code the loop.