Created
May 23, 2012 05:18
-
-
Save anonymous/2773388 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(); | |
car 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].year << " " << carinstock << " $" << carinstock[temp].price << endl; | |
return 0; | |
} | |
car createcar() | |
{ | |
car carinstock; | |
cout << "make: " << endl; | |
cin >> createcar.make | |
cout << "model: " << endl; | |
cin >> createcar.model; | |
cout << "year:" << endl; | |
cin >> createcar.year; | |
cout << "price" << endl; | |
cin >> createcar.price; | |
return createcar; | |
} | |
car mostexpensive (car allcars[5]) | |
{ | |
int largest = 0; | |
for ( int i =0; i < 6; 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