Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

array

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;

                 

                  index++;

            }

            else

            {

                  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;

      }

 

}

0
mhho
Asked:
mhho
  • 2
1 Solution
 
rstaveleyCommented:
> is there a diffrence array  method than what I have so far ....

I think you need to make your question clearer, mhho.
0
 
mhhoAuthor Commented:
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.

0
 
rstaveleyCommented:
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?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now