fork download
  1. /*******************************************************************************
  2.  * Aiden Stannard // CS1A // Chapter 7 Homework: Challange 1# // 10/30/2026
  3.  *
  4.  * Largest/Smallest Value
  5.  *
  6.  * This program recieves 10 values, stores those values in an array of 10
  7.  * elements, and displays the largest and smallest values of the array. The
  8.  * program does not accept negative values.
  9.  *
  10.  * Input
  11.  * Enter 10 numbers: ___
  12.  * Output
  13.  * The largest number in the array is ___
  14.  * The smallest number in the array is ___
  15.  ******************************************************************************/
  16. #include <iostream>
  17. using namespace std;
  18.  
  19. int main()
  20. {
  21. const int size = 10; // Value for the size of the array
  22. double array[size]; // array definition
  23. double large; // stores largest and smallest values assigned to the array
  24. double small;
  25.  
  26. cout << "Enter 10 numbers; " << endl;
  27. cin >> array[0];
  28. // initializes large/small to be the first number entered int the array
  29. large = array[0];
  30.  
  31. for (int count = 1; count < size; count++)
  32. {
  33. cin >> array[count];
  34. while (array[count] < 0) // denies input if negative until a valid number is entered
  35. {
  36. cout << "You cannot enter a negative number. Re-enter number: " << endl;
  37. cin >> array[count];
  38. }
  39. if (array[count] > large) // updates the smallest and largest number of the array
  40. large = array[count];
  41. if (array[count] < small)
  42. small = array[count];
  43. }
  44.  
  45. cout << "The largest number in the array is " << large << endl;
  46. cout << "The smallest number in the array is " << small << endl;
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter 10 numbers; 
The largest number in the array is 6.95304e-310
The smallest number in the array is 4.94066e-324