Here is what I wrote:
#include <iostream>
using namespace std;
struct vetura{
char ngjyra[10];
char tipi[10];
};
int main(){
int i,j;
vetura v[4];
for(i=0;i<4;i++){
cout << "Ngjyra:"<<endl;
cin >> v[i].ngjyra;
cout << "tipi:"<<endl;
cin >> v[i].tipi;
}
j=0;
for(i=0;i<4;i++){
if(v[i].ngjyra == "kuqe" && v[i].tipi == "passat")
j+1;
}
cout<<"kemi "<<j<<" vetura passat me ngjyre te kuqe";
cin.get();cin.get();
return 0;
}
I need to count how many times I have wrote “kuqe” for v[i].ngjyra and “passat” for v[i].tipi together. I thought the variable j is going to get bigger everytime it counts but it is not working and I am going to have an exam in the following hours can anyone help me?
You have two problems:
First:
Change:
to:
Or simpler:
Second:
v[i].ngjyra == "kuqe"will never be true. You are checking whether the location ofv[i].ngjyrais the same as the location of"kuqe". And it isn’t.If you want to test whether the character strings have the same value, change:
to: