» »

c++ vector napaka!!

c++ vector napaka!!

kretze ::

 any help???

any help???




#include <iostream>   
#include <stdlib.h> 
#include <string> 
#include<vector>
#include<iomanip>
using namespace std;


void initVectors(vector <int>&id, vector<int>&units, vector<double>&prices)
{


	for (int i = 914; i <= 922; i++)
		id.push_back(i);



	units.push_back(842);
	units.push_back(416);
	units.push_back(127);
	units.push_back(514);
	units.push_back(514);
	units.push_back(437);
	units.push_back(269);
	units.push_back(97);
	units.push_back(492);
	units.push_back(212);

	prices.push_back(12.95);
	prices.push_back(14.95);
	prices.push_back(18.95);
	prices.push_back(16.95);
	prices.push_back(21.95);
	prices.push_back(31.95);
	prices.push_back(14.95);
	prices.push_back(14.95);
	prices.push_back(16.95);

		
}


void calsSales(vector<int>units, vector<double>prices, vector<double>&sales)
{
	for (int i = 0; i< units.size(); i++)
		sales.push_back(units[i]*prices[i]);
}
void dualSort(vector<int>&id, vector<double>&sales)
{
	int maxIndex, temp, size;
	double maxValue;
	size = id.size();

	for (int i = 0; i < (size - 1); i++)
	{
		maxIndex = i;
		maxValue = sales[i];
		temp = id[i];
		for (int j = i + 1; j < size; j++)
		{
			if (sales[j] > maxValue)
			{
				maxValue = sales[j];
				temp = id[j];
				maxIndex = j;
			}
		}
		sales[maxIndex] = sales[i];
		id[maxIndex] = id[i];
		sales[i] = maxValue;
		id[i] = temp;
	}
}


void showOrder(vector<double>sales, vector<int>id)
{
	cout << "Product namber\tSales\n";
	cout << "---------------------------------------\n;";
	for (int i = 0; i < id.size(); i++)
	{
		cout << id[i] << " \t\t$";
		cout << setw(8) << sales[i] << endl;
	}
	cout << endl;
}


void showTotals(vector<double>sales, vector<int>units)
{
	int totalunits = 0;
	double totalSales = 0.0;
	for (int i = 0; i < units.size(); i++)
	{
		totalunits += units[i];
		totalSales += sales[i];
	}
	cout << "total units sold " << totalunits << endl;
	cout << "total sales " << totalSales << endl;
}


int main()
{
	vector<int>id;
	vector<int>units;
	vector<double>prices;
	vector<double>sales;

	initVectors(id, units, prices);
	calsSales(units, prices, sales);

	dualSort(id, sales);
	cout << fixed << showpoint << setprecision(2);
	showOrder(sales, id);
	showTotals(sales, units);

	system("pause");// 
	return 0;
}

BivšiUser2 ::

Najprej pokaži napredek pri prejšnji nalogi (Nogomet).
SloTech - če nisi z nami, si persona non grata.

kretze ::

prejšnje naloge mi ni uspelo rešit z stringi sem jo rešil pa z chari.


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

c++ rabim pomoč konstuktorji

Oddelek: Programiranje
61098 (793) Snowflake2
»

[C#] Min in Max vrednosti spremenljivk

Oddelek: Programiranje
7779 (506) MrBrdo
»

En easy program v c

Oddelek: Programiranje
5784 (491) XsenO
»

Linux Synaptics touchpad driverji

Oddelek: Operacijski sistemi
121099 (976) preem
»

[C++] Functor za izračun osnovne statistike podatk. strukture (vector,list...)

Oddelek: Programiranje
91480 (1393) Vesoljc

Več podobnih tem