-
-
Save rhysforyou/2773398 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
struct car { | |
char make [20]; | |
char model [20]; | |
int year; | |
int price; | |
}; | |
car createcar(); | |
int mostexpensive (car carinstock[5]); | |
int main() | |
{ | |
car carinstock[5]={ | |
{"Toyota", "Camry", 2002, 23290}, | |
{"Holden", "Barina", 2001, 11000}, | |
{"mazda", "astina", 1993, 8200}, | |
{"ford", "fairmount", 1995, 8500} | |
}; | |
carinstock[4] = createcar(); | |
int temp = mostexpensive(carinstock); | |
cout << carinstock[temp].make << " " << carinstock[temp].model << " " << carinstock[temp].year << " $" << carinstock[temp].price << endl; | |
return 0; | |
} | |
car createcar() | |
{ | |
car newcar; | |
cout << "make: " << endl; | |
cin >> newcar.make; | |
cout << "model: " << endl; | |
cin >> newcar.model; | |
cout << "year:" << endl; | |
cin >> newcar.year; | |
cout << "price" << endl; | |
cin >> newcar.price; | |
return newcar; | |
} | |
int mostexpensive (car allcars[5]) | |
{ | |
int largest = 0; | |
for ( int i = 1; i < 5; i++) | |
{ | |
if (allcars[i].price > allcars[largest].price) | |
largest = i; | |
} | |
return largest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment