Reputation: 1
I've decided to make a sandbox application that will help me practice more with vectors, and the key output of the program is only displayed in the blink of an eye. The window itself is not exiting immediately as I've seen other people dealing with that issue. My program computes an average of n amount of vector int values, which will then be displayed.
#include <iostream>
#include <vector>
using namespace std;
double avgVector(vector<int>);
int main()
{
vector<int> values;
int numValues;
double average;
cout << "How many values do you wish to average? ";
cin >> numValues;
for (int count = 0; count < numValues; count++)
{
int tempValue;
cout << "Enter an integer value: ";
cin >> tempValue;
values.push_back(tempValue);
}
average = avgVector(values);
cout << "Average: " << average << endl;
return 0;
}
double avgVector(vector<int> vect)
{
int total = 0;
double avg = 0.0;
if (vect.empty())
cout << "No values to average.\n";
else
{
for (int count = 0; count < vect.size(); count++)
total += vect[count];
avg = static_cast<double>(total) / vect.size();
}
return avg;
}
The message "Average:" + the average value is displayed in a blink of an eye, and I've tried to include character-capturing functions such as std::cin.get() and std::getChar()
Upvotes: 0
Views: 85
Reputation: 680
Properties -> Linker -> System -> SubSystem
Console (/SUBSYSTEM:CONSOLE)
Press Ctrl + F5 instead, then you will see below:
Upvotes: 0
Reputation: 57784
Run the program in a command line window. That way, after it exits, the output persists.
Upvotes: 0