Stuck on getting highest number output using array

Here is my code and everything works except i can not get the highest array number to be output. it always says 10. Any advice or where I should start looking to fix the problem would be appreciated I am very new to coding so make it in easy terms if possible!


My instructions are:

(1) Create a 10-integer array called data
(2) Set a pointer ptr to point to array data
(3) Output the elements in array data using pointer ptr
(4) Find the largest element in the array data using pointer ptr

#include <iostream>
#include <cstdlib>
using namespace std;


int main(){

float data[10];
cout << "Please enter 10 double numbers: ";

for(int i=0; i<10; i++){
cin >>data[i];
}
{
system("pause");

float *ptr = data;
float *ptr2 = data + 1;
cout << *ptr << endl;
cout << *ptr2 << endl;
cout << *(data + 2) << endl;
}
{


float actualMax=-999, almostMax=-999;
for(int i = 0; i<10; i++){
if(actualMax< data[i]){
actualMax = data[i];
}
}
{

cout << "The maximum is " << actualMax << "." << endl;
}

{

return 0;
}
}
}
Last edited on
Noticed i used Float when instructions said Int but that's trivial to my question lol
highest array number

Do you want to output highest value found in array ({1, 10, 100} = 100) or index of largest element ({1, 10, 100} = 2)?
Find the largest element using a pointer
Last edited on
1
2
3
4
5
int* max = data;
for(int* ptr = data, ptr < data + 10; ++ptr)
    if (*ptr > *max)
        max = ptr;
std::cout << *max;
Topic archived. No new replies allowed.