Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Last active October 21, 2016 05:11
Show Gist options
  • Save olecksamdr/377127ce1c3d3a0f3024dbc9b16f948f to your computer and use it in GitHub Desktop.
Save olecksamdr/377127ce1c3d3a0f3024dbc9b16f948f to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
vector<double> strToIntVector(string& str) {
vector<double> numbers;
stringstream ss(str);
double n;
while(ss >> n) {
numbers.push_back(n);
}
return numbers;
}
int _tmain(int argc, _TCHAR* argv[])
{
string userInput;
cout << "Write a array of numbers like this: \n1 2 3 4 5 6 7 8 9 10 \n\nYour array: ";
getline(cin, userInput);
//cout << userInput;
vector<double> numbers;
numbers = strToIntVector(userInput);
int count = 0;
double sum = 0;
for (int i = 0; i < numbers.size(); i+=3) {
sum += numbers[i];
count++;
}
cout << "count: " << count << endl;
cout << "sum: " << sum << endl;
int a;
cin >> a;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment