Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

I need programming help?

I am working on this program that uses an array of structs and im trying to find the smallest and largest if the number of planes landed but the way i wanna do it is not working ... please help me

#include <iostream>

using namespace std;

struct aircraft

{

int landed;

int departed;

int greatestLanded;

int leastLanded;

};

int main()

{

aircraft plane[6];

int sum = 0;

float avg[2];

int smallest = 99;

int largest = 0;

int smMonth = 0;

int lgMonth = 0;

//loop asks the user those questions 12 times

for(int count = 0; count < 6; ++count)

{

cout << "In month " << (count + 1) << ", how many planes landed? ";

cin >> plane[count].landed;

cout << "In month " << (count + 1) << ", how many planes departed? ";

cin >> plane[count].departed;

cout << "In month " << (count + 1) << ", what is the greatest amount of planes landed in one given day? ";

cin >> plane[count].greatestLanded;

cout << "In month " << (count + 1) << ", what is the fewest amount of planes landed in one given day? ";

cin >> plane[count].leastLanded;

cout << endl;

}

//adds up the total of planes landed

for (int count = 0; count < 6; ++count)

sum += plane[count].landed;

avg[1] = sum / 6; // calculates the average of landed

cout << "The average of planes landed is " << avg[1] << endl;

sum = 0; //resets sum to zero

//adds up the total of planes departed

for (int count = 0; count < 6; ++count)

sum += plane[count].departed;

avg[2] = sum / 6; // calculates the average for departed

cout << "The average of planes departed is " << avg[2] << endl;

sum = 0;

//Calculates the total of planes landed and departed

for (int count = 0; count < 6; ++ count)

{

sum += plane[count].departed;

sum += plane[count].landed;

}

cout << "The total planes landed and departed is " << sum << endl;

//finds the largest and smallest amount of planes laneded and departed

for (int count = 0; count < 6; ++count)

{

if(plane[count].landed >= smallest)

{

plane[count].landed = smallest;

count = smMonth;

}

else if(plane[count].landed <= largest)

{

plane[count].landed = largest;

count = lgMonth;

}

}

cout << "The month with the fewest amount of planes landed is month ";

cout << smMonth << " and it had " << smallest << endl;

cout << "The month with the largest amount of planes landed is month ";

cout << lgMonth << " and it had " << largest << endl;

system("PAUSE");

return 0;

1 Answer

Relevance
  • 1 decade ago

    //finds the largest and smallest amount of planes landed and departed

    for (int count = 0; count < 6; ++count){

    ...if(plane[count].landed <= smallest){

    ......smallest = plane[count].landed;

    ......smMonth = count + 1;

    ...}

    ...if(plane[count].landed >= largest){

    ......largest = plane[count].landed;

    ......lgMonth = count + 1;

    ...}

    }

    replace this section, then look at your rounding in this section

    //adds up the total of planes landed

    for (int count = 0; count < 6; ++count)

    sum += plane[count].landed;

    avg[1] = sum / 6; // calculates the average of landed

    cout << "The average of planes landed is " << avg[1] << endl;

    sum = 0; //resets sum to zero

    //adds up the total of planes departed

    for (int count = 0; count < 6; ++count)

    sum += plane[count].departed;

    avg[2] = sum / 6; // calculates the average for departed

    cout << "The average of planes departed is " << avg[2] << endl;

    i know you cant have partial planes land or take off, but when i did it i t should have been 7.5 meaning the average should have been 8. FYI

    Source(s): My source is me and my years in the field
Still have questions? Get your answers by asking now.