Posted on 2006-05-11
Last Modified: 2010-04-01
is there a diffrence array  method than what I have so far ....

#include <iostream>

#include <string>

using namespace std;


struct cartype


    string make;

    string model;

    double mileage;

    float price;

    int year;



//Functions prototypes section


// readCars function reads from the user the informtion

// of all the cars in stock

int readCars(cartype *);


// displayCars function displays all the cars in stock

void displayCars(cartype *, int);

int readCars(cartype *cars)


      int index = 0;

      bool stop = false;

      char userInput;

      while (!stop)


            cout << endl << "please enter 'c' to continue or any other character to quit ==>";

            cin >> userInput;

            if (toupper(userInput) == 'C')


                  cout << "Enter Make ==> ";

                  cin >> cars[index].make;

                  cout << "Enter Model ==> ";

                  cin >> cars[index].model;

                  cout << "Enter Mileage ==> ";

                  cin >> cars[index].mileage;

                  cout << "Enter Price ==> ";

                  cin >> cars[index].price;

                  cout << "Enter Year ==> ";

                  cin >> cars[index].year;






                  stop = true;



      cout << "index is : " << index << endl;

      return index;




// displayCars 'void' function displays the elements of the array cars[]


void displayCars(cartype *cars, int numOfCars)


      int index;

      for (index=0; index < numOfCars; index++)


            cout << "Enter Make: " << cars[index].make << endl;

            cout << "Enter Model: " << cars[index].model << endl;

            cout << "Enter Mileage: " << cars[index].mileage << endl;

            cout << "Enter Price: " << cars[index].price << endl;

            cout << "Enter Year: " << cars[index].year << endl;

            cout << endl;




Question by:mhho
    LVL 17

    Expert Comment

    > is there a diffrence array  method than what I have so far ....

    I think you need to make your question clearer, mhho.

    Author Comment

    Ok What would  its take an array of cartype and its number of elements and decreases the price by 'amount' for the cars that have make equals to 'make' variable.

    LVL 17

    Accepted Solution

    You've shown in displayCars that you know how to use an index to get a reference to a car type.

    You've shown that you can display the car's make with cars[index].make.

    You can compare a std::string simply with operator==.

       e.g.  if (cars[index].make == required_make)

    You can adjust the price, having tested the make.

       e.g. cars[index].price -= required_amount

    Is this a homework assignment?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now