0

I have a vector that with your help I succeeded to make it work just fine.
Now I want to make the same vector to work with float values but just doesn't want to make me the mathematics with float numbers.
Is adding only the integers and not the float numbers.

#include <vector>
#include <numeric>
#include <functional>
#include <iostream>
using namespace std;
typedef vector<float> VECTORINT;
typedef vector<int> VECTORINT1;
int main()
{
	VECTORINT Vectorul;
	VECTORINT1 Categorii;
	//int y;
	float x;
	int num;
	int categ;
	float  total = 0.00; //sum?
	int total_categ;
	
	cout<<"Introduceti the number of dimensions: ";
	cin >> num;  //the number of numbers that must be entered
 
	for( float i = 0; i < num; i++ )
	{
		cout<<"Introduce the dimensions: ";
		cin >> x;
		//y += x; //either add them here
		Vectorul.push_back(x);
		//for( int j = 0; j < Vectorul.size(); j++ ) //do not nest for() loops with the same variable
			//cout << Vectorul[j] << endl; //seems kinda pointless and just clutters the input/output
	}
	cout<<"Introdfuce the numbers of categories: ";
	cin>>categ;
	for(int j = 0; j<categ; j++)
		cout<<"Introduceti categoriile: ";
		cin>>y;
	Categorii.push_back(y); 
 
	//for( int i = 0; i < Vectorul.size(); i++ )
	//y += Vectorul[i]; //or add them here BUT do not include both of these sections
	//cout<<y<<endl;
    total = accumulate(Vectorul.begin(), Vectorul.end(), 0);
    cout<<total;
	/total_categ = accumulate(Categorii.begin(), Categorii.end(), 0);
	cout<<total_categ; 
	system("pause");
	return 0;
}

I beat my head all night at work what to do but I couldn't find any solution.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by eduard77
0

If you are going to use the accumulate function to add floating-point numbers together, the third argument has to be 0.0, not 0

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.