Wątek przeniesiony 2018-01-18 19:53 z C/C++ przez kq.

Dlaczego nie mogę użyć zmiennej, której nie ma?

0
#include <iostream>

using namespace std;




    struct car
                {
                    string brand;
                    int year;
                    int milleage;
                    float price;
                    bool crash;
                    float engine;
                    string color;
                    int power;
                };

    int find_the_youngest_car(car tab_cars[],int max_nr);

int main()
{
    int max = 5;
    car cars[max] =
    {
        {"Volkswagen", 2009, 1232180, 12341, 1, 1.9, "black" , 150},
        {"Skoda", 2006, 160000, 11000, 0, 1.9, "blue" , 105},
		{"Ferrari", 2017, 13000, 100000, 0, 5.5, "red" , 340},
		{"Bugatti", 2015, 40000, 150000, 0, 6.0, "green" , 510},
		{"Toyota", 2006, 230000, 8000, 0, 1.4, "gray" , 80}
	};
	cout<<"Najmlodzszy rocznik samochodu to : "<<find_the_youngest_car(cars,max);



    return 0;
}

	    int find_the_youngest_car(car tab_cars[],int max_nr)
    {
        int i=0;
        int the_youngest=cars[i].year;
        for(int i;i<max_nr;i++)
        {
            if(cars[i].year<cars[i+1].year)
                the_youngest=cars[i+1].year;
        }
        return the_youngest;
    }

może mi ktoś z tym pomóc? nie wiem na czym polega błąd

"cars wasnt declared in this scope"

2

W find_the_youngest_car() nie masz czegoś takiego jak cars, masz tab_cars.

1 użytkowników online, w tym zalogowanych: 0, gości: 1