Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct CityPollution
- {
- string name;
- int id;
- float pollution[5], totalPollution=0;
- };
- void displayAllData(CityPollution);
- int main()
- {
- CityPollution city0;
- cout << "Area name: ";
- cin >> city0.name;
- cout << "ID number: ";
- cin >> city0.id;
- for (int i=0; i<5; i++)
- {
- cout << "Pollution reading " << i+1 << " : ";
- cin >> city0.pollution[i];
- city0.totalPollution += city0.pollution[i];
- }
- displayAllData(city0);
- ofstream dataFile("pollutionData.txt");
- dataFile << "City name: " << city0.name << endl;
- dataFile << "City ID: " << city0.id << endl;
- dataFile << "Total pollution: " << city0.totalPollution;
- dataFile.close();
- }
- void displayAllData(CityPollution city0)
- {
- cout << "\nCity name: " << city0.name << endl;
- cout << "City ID: " << city0.id << endl;
- cout << "Total pollution: " << city0.totalPollution;
- }
Add Comment
Please, Sign In to add comment