Hi please help me for this code, asking to mark both the smallest and the largest element.
I just got largest, didn't get smallest number. thanks, I appreciate your help
here is code:
#include <iostream>
using namespace std;
int main()
{
const int CAPACITY = 1000;
double values[CAPACITY];
int current_size = 0;
cout << "Please enter values, Q to quit:" << endl;
double input;
while (cin >> input)
{
if (current_size < CAPACITY)
{
values[current_size] = input;
current_size++;
}
}
double largest = values[0];
for (int i = 1; i < current_size; i++)
{
if (values[i] > largest)
{
largest = values[i];
}
}
for (int i = 0; i <current_size; i++)
{
cout << values[i];
if (values[i] == largest)
{
cout << " <== largest value";
}
}
double smallest = values[1];
for (int j = 0; j < current_size; j++)
{
if (values[j] > smallest)
{
smallest = values[j];
}
}
for (int j = 1; j < current_size; j++)
{
cout << values[j];
if (values[j] == smallest)
{
cout << " <== smallest value";
}
}
cout << endl;
return 0;
}
I think I did put double largest and smallest at the begining of each function. Darkmaster if you don't mind can you fix mine and post in here. It will help me understand more. Bzecause I'm just a beginner. Thanks
This could also be done in real time as the input is coming in, to optimize the program.
Alos, keep in mind that if you only had one value it would be both the largest and smallest value in the array. Probably want to set your initial largest and smallest to the first value from input.