Those some parts of my program. I write the problem at the buttom

void main()
{
	string option;

	warehouse car[2];

	car[0].inputCar("lamborgini",true);
	car[0].showCar();
	car[1].inputCar("ferrari",false);
	car[1].showCar();

		//display the choices of the user
		cout<<"a) Show number of modified"<<endl;
		cout<<"b) Show list of modified"<<endl;
		
		cin>> option;

	switch (option[0])
	{
		case 'a':
			countModified();
			break;
		case 'b':
			listModified();
			break;
	}
}//end main

my function

void listModified()
{
	warehouse car[2];


for (i=0;i<2;i++)
	{
		car[i].printModified();
		//cout<<"COUT: "<<car[i].checkModified()<<endl;
	}


}

i noticed that i must have warehouse car[2]; to every function i write elsewhere i get the following errors

error C2065: 'car' : undeclared identifier
and
error C2228: left of '.printModified' must have class/struct/union

the problem is that the values change.
any way to fix this ?

Thanks for your time!

As per my understanding of your problem, you need to declare car as a global variable and you'll be able to access it from everywhere without redeclaration.

Also, you have not defined "option" variable used on line 16 and 18. On line 16, you are treating as a simple variable whereas on line 18, you are treating it as an array.

Hello, thanks for your time helping me.

I tried to declare it globally but doesn`t work.

also here my full code

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int i=0;
int total=0;
int check=1;

void listModified();

class warehouse
{
public:
    warehouse()
    {
    PRVmodified=true;
    }

    void printModified();
    void checkModified();
    void inputCar(char car[20],bool modified);
    void showCar();
private:
    char PRVcar[20];
    bool PRVmodified;

};
void warehouse::inputCar(char car[20],bool modified)
{
    strcpy(PRVcar,car);
    PRVmodified=modified;
}

void warehouse::showCar()
{
    cout<<"car model is: "<<PRVcar<<endl;
    cout<<"car is modified: "<<PRVmodified<<endl<<endl;
}
void warehouse::checkModified()
{
if (PRVmodified == 1)
{
            ++total;
            
}

}
void countModified()
{
    warehouse car[2];
    
    for (i=0;i<2;i++)
    {
        car[i].checkModified();
    }
    cout<<"The total cars modified: "<<total<<endl;
}

void warehouse::printModified()
{
if (PRVmodified == 1)
{
    cout<<"the car that is modified: "<<endl;
            
}
}
void listModified()
{
for (i=0;i<2;i++)
    car[i].printModified();

}
void main()
{
    string option;

    warehouse car[2];

    car[0].inputCar("lamborgini",true);
    car[0].showCar();
    car[1].inputCar("ferrari",false);
    car[1].showCar();

        //display the choices of the user
        cout<<"a) Show number of modified"<<endl;
        cout<<"b) Show list of modified"<<endl;
        
        cin>> option;

    switch (option[0])
    {
        case 'a':
            countModified();
            break;
        case 'b':
            listModified();
            break;
    }
}//end main

Where have you declared it globally? Its only local declaration withing main at line 78. For global declaration, declare it outside every function and class. For ex-

warehouse car[2];
void main()
{
.
.
.
}

Don't declare it globally. Your teacher will take points off. Instead do this:

void listmodified(Car car[], int size){
 /* some code here */
}
int main(){
 warehouse car[2];
 /* some code here */
 listmodified(car);
}

so that way you are using the same car thats in main inside of the function listmodified.

It works with global variable, but i wanted to make it work with passigf the arguements..
I fix it and work with arguements now.
Just have to change

countModified(car);
and
void listModified(warehouse ArrayOfStruct[]) ;

Topic solved!

Thanks for the help!

I would like to add that you should not be using void main. per the c++ standard main should always return a int.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.