Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Vehicles
- {
- string car_model;
- string car_make;
- int car_mileage;
- int car_year;
- };
- /* function phrams naming is not the same
- as your varitables name, and it uses
- its own naming schem inside of itself
- */
- void getData(Vehicles a[],int s);
- void output( Vehicles v[], int size);
- int main(){
- int amount;
- cout<<"Enter amount of cars to be logged\n";
- cin>>amount;
- Vehicles var[amount];
- getData(var,amount);
- output(var,amount);
- return 0;
- }
- void getData(Vehicles a[],int s)
- { /* use finctions naming inside
- itself
- */
- char run='y';
- for(int i = 0; i < s; i++)
- { /* you can pass striaght into
- the members, saving time and
- memory by not using extra data vars
- */
- cout
- <<" Input the Car Model for car number "
- "<"
- <<i+1
- <<">"
- << endl;
- cin >> a[i].car_model;
- cout << "Input the Car Make ";
- cin >> a[i].car_make;
- while(run=='y'){
- cout << "Input Car mileage:" << endl;
- /* error handling bad input char for int */
- cin >> a[i].car_mileage;
- if(!cin){
- cin.clear();
- cin.ignore(
- numeric_limits<streamsize>::max(),
- '\n');
- /*.ask again */
- continue;
- }else{
- run='n';
- }
- }/* reset for next loop */
- run='y';
- while(run=='y'){
- cout << "Input Car Year:" << endl;
- cin >> a[i].car_year;
- if(!cin){
- cin.clear();
- cin.ignore(
- numeric_limits<streamsize>::max(),
- '\n');
- continue;
- }else{
- run='n';
- }
- }
- }
- }
- void output( Vehicles v[], int size )
- {
- /*
- this formatting style is of
- my own makes it easier to
- change things;
- */
- for ( int i = 0; i < size; i++)
- {
- cout
- <<endl
- <<endl
- << "("
- <<i+1
- <<")"
- <<"Car Model"
- << "::"
- << v[i].car_model
- << endl;
- cout
- << "Car Make"
- << "::"
- << v[i].car_make
- << endl;
- cout
- << "Car Mileage"
- << "::"
- << v[i].car_mileage
- << endl;
- cout
- << "Car Year"
- << "::"
- << v[i].car_year
- << endl<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment