invalid conversion of int* to int

Hello everyone,

I am doing a module for my programming class where I have to find the lowest and highest temperature and print it and I was going to kind of use a bubble sort but it says "invalid conversion of int* to int" because it is an array.

This is part of the array and the part where I am having problems:
for (k=1;k<8;k++){
cout << "Enter temperature for day " << k << ":";
cin >> temperature[i][k];
cout << "Temperature day " << k <<": "<< temperature[i][k] << endl;
if (k=2)
{ if(temperature[i]>temperature[i-1])
high=temperature[i];
else if (temperature[i]>temperature[i-1])
low=temperature[i];
}
}

This is inside of another array(i) and I am trying to get it to where it finds a low and high temp and then print it! Would really appreciate some help.

I know I am probably doing this in a complicated/not good practice way but I have finals in 2 days and this pretty much the last thing I need to do before it.
First, use code tags:
http://cplusplus.com/articles/z13hAqkS/

Anyway, it looks like temperature is a 2d array, so you can't assign an entire 1d array to this int "high" you have inside your if statement.
I see what you mean and realized my mistake. But now it seems like it is getting stuck at Temperature for day 3. There are no errors in compiling, just when I run the program.
if (k=2) is an assignment, so k will never get passed 3.

Also, that logic is wrong - you want to perform the checks for all k >= 1, not just when k == 2.

Edit: As you're filling the array from 1 to 7, the check should be k >= 2.

Cheers
Jim
Last edited on
Thanks a ton! The right code ended up being:
1
2
3
4
5
6
7
8
9
10
11
 
         for (k=1;k<8;k++){ 
         cout << "Enter temperature for day " << k << ":"; 
         cin >> temperature[i][k];
         cout << "Temperature day " << k <<": "<< temperature[i][k] << endl;
         if (k>=2)
         { if(temperature[i][k]>temperature[i][k-1])
         high=temperature[i][k];
         if (temperature[i][k]<temperature[i][k-1])
         low=temperature[i][k];
         } 


edit: Not sure why but if I changed the last if to an else if, it would not work. Not sure if this is due to putting in an equal value and not having a remaining else statement or what, I just ended up choosing this because it worked.
Last edited on
Topic archived. No new replies allowed.