fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. float min;
  5. float temp;
  6. void computeMin(std::vector<float> nums){
  7. //You could just use the vector size() instead of needing the input.
  8. for (int i = 0; i < nums.size(); ++i){
  9. min = (nums[i] < min) ? nums[i] : min;
  10. }
  11. std::cout << "Incorrect Minimum Value: " << min << std::endl;
  12. }
  13.  
  14. void computeCorMin(std::vector<float> numArray){
  15. for (int i = 0; i < numArray.size()-1; i++){
  16. temp = numArray[i+1];
  17. min = (numArray[i] < temp) ? numArray[i] : temp;
  18. }
  19. std::cout << "Correct Minimum Value: " << min << std::endl;
  20. }
  21.  
  22. int main() {
  23. // your code goes here
  24. std::vector<float> arrayTest(3);
  25. arrayTest.push_back(3);
  26. arrayTest.push_back(2);
  27. arrayTest.push_back(1);
  28. arrayTest.push_back(4);
  29.  
  30. computeMin(arrayTest);
  31. computeCorMin(arrayTest);
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Incorrect Minimum Value: 0
Correct Minimum Value: 1