#include <iostream>
usingnamespace std;
int main()
{
int first;
int second;
int amount;
int hold=99999999;
cout<<"How many numbers will you enter?";
cin>>amount;
cout<<"Enter number: ";
cin>>first;
for (int x=1;x<=amount-1;x++)
{
cout<<"Enter number:";
cin>>second;
if (first<second)
{
first=second;
}
if (first&&second<hold)
hold=first&&second;
}
cout<<"highest score: "<<first<<endl;
cout<<"Lowest score: "<<hold;
}
can you show me other ways of doing this without using the variable hold=99999999 ?
#include <iostream>
usingnamespace std;
void getNum(int *);
void testNum(int *, int *, int *);
int main()
{
int low, high, num;
int amount;
cout << "How many numbers will you enter? ";
cin >> amount; cout << endl;
// Get the first number in order to set the initial low and high value
getNum(&num);
low = num;
high = num;
while(amount-1 > 0) // Used amount-1 because we've already entered 1 number
{
testNum(&low, &high, &num);
amount--;
}
cout << "Lowest: " << low << endl;
cout << "Highest: " << high << endl;
return 0;
}
void getNum(int *num)
{
cout << "Enter number: ";
cin >> *num; cout << endl;
}
void testNum(int *low, int *high, int *num)
{
getNum(num);
if(*num < *low) *low = *num;
elseif(*num > *high) *high = *num;
}