The program asks user to enter numbers and stores the numbers in the vector. The program stops asking numbers when user enter a negative number. The negative number is not stored the vector.
When program has finished asking numbers it sorts the numbers. After sorting the program prints the numbers on separate lines with 3 decimal precision.
SPECIFIC QUESTION:
Most of my code is ready I just need to fix the following:
How can I make the program below not to store the negative number in the vector?
Finally, my last line of code is not printing the numbers on separate lines with 3 decimal precision
MY CODE:
#include <iostream>
#include <vector>
#include <iomanip> // std::setprecision
using namespace std;
int main()
{
double values;
int fox;
vector<double> numbers;
cout << "Enter any positive numbers (negative to stop): ";
while (cin >> values) {
if (values < 0) {
break;
}
numbers.push_back(values);
}
int y = numbers.size();
for (int i = 0; i < y; i++) {
cout << numbers[i] << " ";
}
cout << fixed << setprecision(3) << values << " " << endl;
return 0;
}