I am a college student trying to write a program that has a user enter a tracking number, type of animal, and boarding charge. If the user wants to enter more than one set of data then they are able to. I am supposed to then have the program print the list of information. I am stuck in trying to figure out how to keep the information entered if more than one set of information is entered. I am confused completely at how this can be done. Can someone help me?
How would you input the information and let the user decide when they were done putting the info in? I have the output part of the program decently figured out.
#include <iostream>
#include <string>
#include <vector>
struct animal
{
int tracking_number = 0 ;
std::string type ;
double boarding_charge = 0 ;
};
int main()
{
std::vector<animal> list ;
animal a ;
while( std::cout << "enter tracking number (enter a non-positive value (eg. -1) to end input): " &&
std::cin >> a.tracking_number && a.tracking_number >= 0 )
{
std::cout << "type of animal: " ;
std::cin >> a.type ; // assumes that there are no embedded spaces in type
std::cout << "boarding charge: " ;
std::cin >> a.boarding_charge ;
// add this animal to the list of animals
list.push_back(a) ;
}
// print out contents of list
for( const animal& a : list )
std::cout << a.tracking_number << ' ' << a.type << ' ' << a.boarding_charge << '\n' ;
}