I have a class ComplexesSet which represent a set of complexes numbers. I have to use this class to write a program which reads the complex numbers from keyboard and create a menu like that: press 1 to add a number in the set, press 2 to delete a number from set and press 0 to exit the program.
This is my program:
HEADER FILE
#pragma once
#include <iostream>
using namespace std;
#define DIMMAX 10;
class Complex {
int re, im;
public:
Complex() {
re = im = 0;
}
Complex(int re, int im) {
this->re = re;
this->im = im;
}
void display() {
cout << " (" << re << ", " << im << " ) ";
}
int equal(Complex c2); // check the equality between 2 complex numbers.
void read(); // reads a complex number
};
class ComplexesSet {
Complex* v; // the complex numbera array
int dim; // the maximum dimension of the array
int n; // the current number of complex numbers in the set
public:
ComplexesSet();
ComplexesSet(int d);
~ComplexesSet();
void addNumber(Complex); // add a number in set
void deleteNumber(Complex); // delete a number from set
void displaySet(); // display the set
};
METHODS FILE
#include "multime.h"
#include <iostream>
using namespace std;
int Complex::equal(Complex c2) {
if (this->re == c2.re && this->im == c2.im) {
return 1;
}
else {
return 0;
}
}
void Complex::read() {
cout << "Enter the real part: ";
cin >> this->re;
cout << "Enter the imaginary part: ";
cin >> this->im;
cout << endl;
}
ComplexesSet::ComplexesSet() {
cout << "Set of complexes numbers: ";
dim = DIMMAX;
v = new Complex[dim];
n = 0;
}
ComplexesSet::ComplexesSet(int d) {
cout << "ComplexesSet(" << d << ")";
dim = d;
v = new Complex[dim];
n = 0;
}
ComplexesSet::~ComplexesSet() {
cout << "~ComplexesSet" << endl;
if (v) {
delete[] v;
}
v = nullptr;
dim = -1;
n = -1;
}
void ComplexesSet::addNumber(Complex num) {
int ok = 0;
if (n < dim) {
for (int i = 0; i < n; i++) {
if (v[i].equal(num)) {
ok = 1;
i = n + 1;
}
}
if (ok) {
cout << "This element is already in the set.";
}
else {
v[n] = num;
n++;
}
}
else {
cout << "The set is full.";
}
}
void ComplexesSet::deleteNumber(Complex num) {
int i;
if (n != 0) {
for (i = 0; i < n; i++) {
if (v[i].equal(num)) {
break;
}
else {
cout << "This element does not exists.";
}
}
if (i < n) {
n = n - 1;
for (int j = i; j < n; j++) {
v[j] = v[j + 1];
}
}
}
else {
cout << "The set is empty.";
}
}
void ComplexesSet::displaySet() {
cout << "\n The set: {";
if (n) {
for (int i = 0; i < n; i++) {
v[i].display();
}
}
cout << "}.\n\n";
}
MAIN FILE:
#include "multime.h"
#include <iostream>
using namespace std;
int main() {
ComplexesSet m;
Complex num;
int option;
int x;
do {
cout << endl << "1 - ADD A NUMBER\n 2 - DELETE A NUMBER\n 0 - EXIT THE PROGRAM";
cin >> option;
switch (option) {
case 1:
cout << endl << "Enter the number you want to add: ";
num.read();
//? How to call addNumber method from ComplexesSet class?
// m.displaySet ?;
break;
case 2:
cout << endl << "Enter the number you want to delete: ";
num.read();
//? How to call deleteNumber method from ComplexesSet class?
// m.displaySet ?;
break;
}
} while (option >= 1 && option <= 2);
system("pause");
return 0;
}
I got stuck in the main file. How to call the addNumber and deleteNumber methods in order to add and delete a complex number from the set? Also, after pressing "1" or "2", after I read the number, I need to display the set.
Related
I am trying to add commas to a set of numbers in an array.
I have a program that will take in random numbers the length of which are determined by the user's input. These numbers are stored in a pointer array. I made another array to store the converted numbers from int to string. Now I am working on a function to add commas to them. I am having an issue with this function. infoArrayString is the converted numbers of user input from int to string. The issue is in the addCommas function
#include <iostream>
#include <string>
using namespace std;
void validNumber(int & x){
while (cin.fail()){
cout << "ERROR: must be a number, try again ->";
cin.clear();
cin.ignore(1000, '\n');
cin >> x;
}
}
void validNumberPointer(int *& x){
while (cin.fail()){
cout << "ERROR: must be a number, try again ->";
cin.clear();
cin.ignore(1000, '\n');
cin >> *x;
cout << endl;
}
}
void amount(int & userAmount, const int & MIN_INPUT, const int & MAX_INPUT)
{
/*
* Asks how many number they want
*/
cout << "How many numbers? -> ";
cin >> userAmount;
cout << endl;
/*
* check
*/
validNumber(userAmount);
while ((userAmount < MIN_INPUT) or (userAmount > MAX_INPUT)){
cout << "ERROR: number out of range" << endl;
cout << "Please enter numbers in range of " << MIN_INPUT << " to " << MAX_INPUT << " ->";
cin >> userAmount;
}
}
void getInfo(int *& infoArray, int & userAmount){
for(int i = 0; i < userAmount; i++){
cout << "Input number #" << i+1 << " ->";
cin >> *(infoArray+i);
cout << endl;
/*
* check
*/
validNumberPointer(infoArray);
while (*(infoArray+i) < 0){
cout << "ERROR: number out of range" << endl;
cout << "Please enter numbers in range of range -> ";
cin >> *(infoArray+i);
cout << endl;
}
}
}
void convertString(int *& infoArray, string *& infoArrayString, int & userAmount){
for(int i = 0; i < userAmount; i++){
*(infoArrayString +i) = to_string(*(infoArray+i));
}
}
void addCommas(string *& infoArrayString){
for(int i = 0; i < infoArrayString[i].length(); i++){
if(i%3 == 0 and i != 0){
infoArrayString[i] = infoArrayString[i] + ",";
}
}
}
void displayBoard(string *& infoArrayString, int & userAmount){
cout << "The sum of: " << endl;
for(int i = 0; i < userAmount; i++){
cout << *(infoArrayString++) << endl;
}
}
int main() {
const int MIN_INPUT = 2, MAX_INPUT = 11;
int userAmount = MIN_INPUT;
int * infoArray = NULL;
infoArray = new int [MAX_INPUT];
string * infoArrayString = NULL;
infoArrayString = new string [MAX_INPUT];
amount(userAmount, MIN_INPUT, MAX_INPUT);
getInfo(infoArray, userAmount);
convertString(infoArray,infoArrayString,userAmount);
addCommas(infoArrayString);
displayBoard(infoArrayString, userAmount);
}
If there is not specific reason you are using a raw array in C++ you may want to use a std::vector. They are easier to manipulate.
void int_to_string(std::vector<int>& integer_list,
std::vector<std::string>& string_list) {
// You can read integers/strings (with streams) into a
// container directly this function is for demo purposes.
for (auto& element : integer_list)
string_list.push_back(std::to_string(element));
}
You can then pass that vector of strings to a function that modifies each entry to have a comma.
void add_commas_to_strings(std::vector<std::string>& S) {
for (auto& element : S)
element += ',';
}
You may just want the commas for formatting. In that case you don't have to mutate the values of the vector.
If a csv style format is what you are after then you may be after something like this:
// Formats csv file style output.
void format_with_commas(std::vector<std::string>& string_list) {
int line_break = 0;
for (int i = 0; i < string_list.size(); ++i) {
if (line_break == 3) {
std::cout << "\n";
line_break = 0;
}
int is_end = line_break + 1;
if (is_end == 3) {
std::cout << string_list[i];
++line_break;
} else {
std::cout << string_list[i] << ", ";
++line_break;
}
}
}
Now if you really want the user to specify the length of a list perhaps try calling something like:
std::vector<int> user_defined_vector(std::vector<int>::size_type sz) {
return std::vector<int>(sz, 0);
}
The above can be ran like so:
#include <iostream>
#include <vector>
int main() {
std::vector<int> A{1, 2, 3, 4, 5, 6, 7, 8, 9};
std::vector<std::string> B;
int_to_string(A, B);
format_with_commas(B);
auto ten_element_vector_of_ints = user_defined_vector(10);
return 0;
}
This might be a stupid question I'm still very new to coding. For my CS class I was given code for the basics of a boardgame. When I try to run the code it just comes up blank in my console, I tried to print "check" at the very beginning of main but still nothing prints to the console. No errors come up
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>
using namespace std;
class square {
private:
int move;
string message;
char symbol;
public:
square();
void print();
int action();
void set(int, char, string);
};
void print_board(square[], int, int);
void read_board(square[]);
void check_position(int &);
const int board_length = 20;
int main() {
cout << "check";
int current_player = 1, roll;
int player1_position = 0, player2_position = 0;
square the_board[board_length];
srand(time(NULL));
read_board(the_board);
print_board(the_board, player1_position, 1);
print_board(the_board, player2_position, 2);
do {
cout << "\n\n\nPlayer " << current_player << " type enter to roll.\n";
cin.ignore();
roll = 1 + (rand() % 5);
cout << "Player " << current_player << " rolled a " << roll << ".\n";
if (current_player == 1) {
player1_position += roll;
check_position(player1_position);
player1_position += the_board[player1_position].action();
check_position(player1_position);
} else {
player2_position += roll;
check_position(player2_position);
player2_position += the_board[player2_position].action();
check_position(player2_position);
}
print_board(the_board, player1_position, 1);
print_board(the_board, player2_position, 2);
current_player = (current_player % 2) + 1;
} while ((player1_position < board_length-1) && (player2_position < board_length - 1));
current_player = (current_player % 2) + 1;
cout << "\nPlayer " << current_player << " Wins!!!\n";
cin.ignore();
return 0;
}
void read_board(square b[]) {
ifstream infile;
infile.open("game.txt");
int square_number, square_move;
string square_message;
char square_symbol;
while (!infile.eof()) {
infile >> square_number >> square_move >> square_symbol;
getline(infile, square_message);
if (square_number < board_length) {
b[square_number].set(square_move, square_symbol, square_message);
}
}
}
void print_board(square b[], int player_position, int player_number) {
for (int i=0; i < board_length; i++) {
if (i != player_position) {
b[i].print();
} else {
cout << player_number;
}
}
cout << "Goal\n";
for (int i=0; i < board_length; i++) {
cout << "-";
}
cout << "\n";
}
void check_position(int &p) {
if (p < 0) {
p = 0;
}
if (p >= board_length) {
p = board_length - 1;
}
}
square::square() {
symbol = ' ';
move = 0;
message = "";
}
int square::action() {
cout << message << endl;
return move;
}
void square::print() {
cout << symbol;
}
void square::set (int m, char s, string a_message) {
move = m;
symbol = s;
message = a_message;
}
Modify you read_board() to
void read_board(square b[]) {
ifstream infile;
infile.open("game.txt");
int square_number, square_move;
string square_message;
char square_symbol;
while (infile >> square_number >> square_move >> square_symbol) {
getline(infile, square_message);
if (square_number < board_length) {
b[square_number].set(square_move, square_symbol, quare_message);
}
}
}
Change cout<<"check"; to cout<<"check"<<endl;
Without the new line added, the out buffer is not flushed before your code gets hung in your read_board function
I am using C++ and want to do a 2-dimensional array. 10 rows and 3 columns. First column is(1 through 10). For Second column, user enters his/her choice of a number from (1-10) resulting in a times table displaying the results as follows: In this example the user's choice is '4':
1x4=4
2x4=8
3x4=12
4x4=16
5x4=20
6x4=24
7x4=28
8x4=32
9x4=36
10x4=40
I can't get the user's input to calculate correctly when using the for loop.
Well you can try this to get that output
#include<iostream>
using namespace std;
int main()
{
int n; //To take input
int table[10][3]; // Table
cout << "Input a number: ";
cin >> n;
// Generating Output
for (int i = 0; i < 10; i++)
{
table[i][0] = i + 1;
table[i][1] = n;
table[i][2] = table[i][0] * table[i][1];
}
for (int i = 0; i < 10; i++)
{
cout << table[i][0] << " * " << table[i][1] << " = " << table[i][2]<<endl;
}
return 0;
}
Output
SOLVED: Everything seems to be working now!! Here's the code:
#include <iostream>
#include<cstdlib>
#include<iomanip>
#include <ctime>
using namespace std;
void displayTable(int table[10][3]);
bool testMe(int testTable[10][3]);
void createTables(int testTable[10][3], int ansTable[10][3], int
usersChoice);
bool AllAnswersAreTested(bool tested[10]);
void gradeMe(int testTable[10][3], int ansTable[10][3]);
void displayMenu();
int main()
{
srand(time(NULL));
int userInput = 0;
int tableChoice = 0;
int myTable[10][3] = {0};
int testTable[10][3];
int ansTable[10][3];
bool tested = false;
do
{
displayMenu(); //Display the menu of choices
cin >> userInput;
cout << endl;
switch (userInput) //Validate menu choices 1-4
{
case 1: //Display a users choice of table
displayTable(myTable);
break;
case 2: //Test user on users choice of table
cout << "What times table test would you like to take? > ";
cin >> tableChoice;
createTables(testTable, ansTable, tableChoice);
tested = testMe(testTable);
if (tested)
{
gradeMe(testTable, ansTable);
}
break;
case 3: //Display a new table of the users choice
displayTable(myTable);
break;
case 4: //Quit program menu option
cout << "Program ending.\n";
return 0;
default: //Invalid entry
cout << "You entered an invalid item number. Please enter a number from 1 to 4.\n";
cout << endl;
}
} while (userInput != 4);
return 0;
}
void displayTable(int myTable[10][3])
{
int num; //initialize local variables
//Ask the user what times table they would like to review
cout << "What times table would you like to review?" << endl;;
cout << "Please enter a value from 1 to 12 > \n";
cout << "\n";
cin >> num;
cout << endl;
for (int i = 0; i < 10; i++)
{
myTable[i][0] = i + 1;
myTable[i][1] = num;
myTable[i][2] = myTable[i][0] * myTable[i][1];
}
for (int i = 0; i < 10; i++)
{
cout << setw(3)<< myTable[i][0] << " * " << myTable[i][1] << " = " << myTable[i][2] << endl;
}
cout << endl;
}
void createTables(int testTable[10][3], int ansTable[10][3], int usersChoice)
{
for (int i = 0; i < 10; i++)
{
testTable[i][0] = i + 1;
testTable[i][1] = usersChoice;
testTable[i][2] = 0;
ansTable[i][0] = i + 1;
ansTable[i][1] = usersChoice;
ansTable[i][2] = usersChoice * (i + 1);
}
}
bool testMe(int testTable[10][3])
{
bool tested[10] = { false, false, false, false, false,false, false, false, false, false };
while (!AllAnswersAreTested(tested))
{
int index = rand() % 10;
if (tested[index] == false)
{
int randomNum = testTable[index][0];
int tableChoice = testTable[index][1];
int answer;
cout << "What is " << randomNum << " X " << tableChoice << " = ";
cin >> answer;
testTable[index][2] = answer;
tested[index] = true;
}
}
return true;
}
bool AllAnswersAreTested(bool tested[10])
{
for (int i = 0; i < 10; i++)
{
if (tested[i] == false)
{
return false;
}
}
return true;
}
void gradeMe(int testTable[10][3], int ansTable[10][3])
{
int correctAnswers = 0;
for (int i = 0; i<10; i++)
{
if (testTable[i][2] == ansTable[i][2])
{
correctAnswers++;
}
}
int score = (correctAnswers * 10);
if (score == 100)
{
cout << "You passed the test! PERFECT SCORE!!" << endl;
cout << endl;
}
else if (score >= 70)
{
cout << "You passed the test. Your Score is: ";
cout << score;
cout << endl;
}
else if (score < 70)
{
cout << "You did not pass the test. Your Score is: ";
cout << score;
cout << endl;
}
}
//Display the menu function
void displayMenu()
{
cout << " Multiplication Tables" << endl;
cout << endl;
cout << " 1. Review MyTable" << endl;
cout << " 2. Test Me" << endl;
cout << " 3. Enter a New Multiplication Table (1-12)";
cout << " 4. Quit" << endl;
cout << " Enter a Menu Item > ";
}
#include <iostream>
using namespace std;
int main()
{
int a[100][100];
for(int i=1;i<10;i++){
for(int j=1;j<10;j++){
a[i][j] = (i)*(j);
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
There is how the output looks like:
The program should read n resistances and a voltage from the keyboard and then calculate the equivalent resistance and the current.
My problem is that it calculates based only on the last entered resistance.
Is it possible to declare a method inside a function? or should I give up this completely unpractical approach
#include "stdafx.h"
#include<iostream>
#include<conio.h>
using namespace std;
class rez {
float r;
public:
void set(int n);
float val() { return r; }
};
void rez :: set(int n) { //n is the number of resistances
int i;
for (i = 1; i <= n; i++) {
cout << "R" << i << "=";
cin >> r;
}
}
float serie(rez r1,int n)
{
float s=0;
int i;
for (i = 1; i <= n; i++)
{
s = s+ r1.val();
}
return s;
}
float para(rez r1, int n)
{
float s = 0;
int i;
for (i = 1; i <= n; i++)
{
s = s + (1/r1.val());
}
return 1/s;
}
int main()
{
char c, k = 'y'; // 'c' selects series or para
rez r1;
int n;
cout << "number of resis:";
cin >> n;
cout << endl;
while (k != 'q')
{
r1.set(n);
float i, u;
cout << "\n Vdc= ";
cin >> u;
cout << endl;
cout << "series or para(s/p)?"<<endl;
cin >> c;
switch (c)
{
case('s'):cout <<"\n equiv resistance = "<< serie(r1,n)<<endl;
i = u / serie(r1, n);
cout << "curr i = " << i << " amp";
break;
case('p'):cout << "\n equiv res = " << para(r1, n)<<endl;
i = u / para(r1, n);
cout << "cur i = " << i << " amp";
break;
}
cout <<endl<< "\n another set?(y/q)?"<<endl;
cin >> k;
}
return 0;
}
It is because when you read in the resistances you are setting the value of the total resistance each time not adding to the total resistance.
void rez :: set(int n) { //n is the number of resistances
int i;
for (i = 1; i <= n; i++) {
cout << "R" << i << "=";
cin >> r; // <- this sets the value of r, it does not add to it
}
}
To fix this you should create a temporary variable to store the input resistance and then add it to the total resistance
void rez :: set(int n)
{
int i;
for (i = 1; i <= n; i++)
{
float input;
cout << "R" << i << "=";
cin >> input;
r += input;
}
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I was given a assignment in college. I was asked to create a c++ console application that would read in five countries from a simple .txt file and allow a user to allocate each team a vote [6, 8, 10, 12]. Each team may vote only once, no duplicate scores and they may not vote for themselves.
We have to then display the scores in descending order to the user using a bubble sort. Practically every element of the application was working up until I had to print the scores in order.
I'm having difficulty with the calculation of the total score and also with the while loop in 'getValidCountry()'
#include <iostream>
#include <fstream> // include the 'fstream' standard library header file
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
//VARIABLES
#define POINTS 4
#define NUM_COUNTRIES 5
int points[POINTS] = {6, 8, 10, 12};
vector<string> countries;
int countryInd[NUM_COUNTRIES] = {0, 1, 2, 3, 4};
int votes [NUM_COUNTRIES][NUM_COUNTRIES];
int voteTotal[NUM_COUNTRIES] = {0,0,0,0,0};
//METHOD HEADINGS
void printarray (int arg[], int length);
void voting(int votingCountry);
int getValidVote();
void printRankedTable();
void printContestants();
void BubbleSort(int arr[], int n);
void resetPoints();
int getValidCountry();
int main ()
{
ifstream inFile;
inFile.open("countries.txt"); // bind the inFile stream to a file name
if( !inFile ) // test to see if it opened successfully
{
cout << "Failed to open file." << endl;
exit( EXIT_FAILURE );
}
int i = 0;
string str;
string fileContents;
//RESERVE 5 SPACES IN THE VECTOR
countries.reserve(NUM_COUNTRIES);
vector<string>::iterator iter;
while( getline( inFile, str ) )
{
countries.push_back(str);
}
inFile.close();
printContestants();
int round = 5;
int cInd = -1;
while(round > 0)
{
cout << endl;
cInd = getValidCountry();
voting(cInd);
BubbleSort(voteTotal, NUM_COUNTRIES);
printRankedTable();
cInd = -1;
round--;
}
}
int getValidCountry()
{
bool temp = false;
string foo;
cout << "Enter Country You Wish To Vote For: ";
getline(cin, foo);
while(!temp)
{
for(int i = 0; i < NUM_COUNTRIES; i++)
{
if(foo.compare(countries.at(countryInd[i])) == 0)
{
temp = true;
return countryInd[i];
}
}
cout << "[ERROR]: Enter A Valid Country: ";
getline(cin, foo);
}
return -1;
}
void printarray (int arg[], int length) {
for (int n=0; n<length; ++n)
cout << arg[n] << ' ';
cout << '\n';
}
void voting(int votingCountry)
{
int score = 0;
for(int i = 0; i < NUM_COUNTRIES; i++)
{
if(countryInd[i] != votingCountry)
{
cout << "Please Enter Score For " << countries.at(countryInd[i]) << ": ";
score = getValidVote();
cout << score << endl;
voteTotal[countryInd[i]] = voteTotal[countryInd[i]] + score;
cout << "vote total: " << voteTotal[countryInd[i]] << "\t CountryInd: " << countryInd[i] << endl;
}
}
resetPoints();
cout << endl;
}
void resetPoints()
{
points[0] = 6;
points[1] = 8;
points[2] = 10;
points[3] = 12;
}
int getValidVote()
{
bool isValid = false;
int vote;
while(!isValid)
{
cin >> vote;
for(unsigned int i = 0; i <= POINTS; i++)
{
if (vote == points[i] && vote > -1)
{
isValid = true;
points[i] = -1;
return vote;
}
}
cout << "Enter Valid Score: ";
}
return 0;
}
void printContestants()
{
cout << endl << "EUROVISION CONTESTANTS\n";
for(unsigned int i = 0; i < NUM_COUNTRIES; i++)
{
cout << countries[countryInd[i]] << endl;
}
cout << endl;
}
void printRankedTable()
{
cout << endl << "EUROVISION CONTESTANTS [RANKED]\n";
for(unsigned int i = 0; i < NUM_COUNTRIES; i++)
{
cout << countries.at(countryInd[i]) << "\t" << voteTotal[i] << endl;
}
cout << endl;
}
void BubbleSort(int arr[], int n)
{
bool swapped = true;
int j = 0;
int tmp;
int tmpC;
while (swapped)
{
swapped = false;
j++;
for (int i = 0; i < n - j; i++)
{
if (arr[i] < arr[i + 1])
{
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
tmpC = countryInd[i];
countryInd[i] = countryInd[i+1];
countryInd[i+1] = tmpC;
swapped = true;
}
}
}
}
The problem:
When you are voting(), you enter the score to voteTotal using countryInd index:
voteTotal[countryInd[i]] = voteTotal[countryInd[i]] + score; // in voting()
So you expect that the order of the countries names and their related score id both use the access sequence defined in countryInd[].
// score of countries.at(countryInd[i]) corresponds to valueTotal[countryInd[i]]
When you BubbleSort(), you swap the elements in both countryInd[] AND in voteTotal[]. This is the cause of your problem, because the right access sequence for the country names is still countryInd[i] but it's now i for the score:
//score of countries.at(countryInd[i]) corresponds now to valueTotal[i]
You already know this, because that's exactly the logic you use in printRankedTable()
Unfortunately, when you take the second voting run, you assume again that both tables use the same access sequence defined in countryInd[] , which is an hypotheses which is no longer valid. You end up adding the voting given for one country to the total of another.
The solution
Change in BubbleSort() the if clause as follows:
if (arr[countryInd[i]] < arr[countryInd[i + 1]]) // indirect access through countryInd
{
//tmp = arr[i]; delete => no longuer needed
//arr[i] = arr[i + 1]; delete => no longuer needed
//arr[i + 1] = tmp; delete => no longuer needed
tmpC = countryInd[i];
countryInd[i] = countryInd[i + 1];
countryInd[i + 1] = tmpC;
swapped = true;
}
Also update the printRankedTable() the output instruction to:
cout << countries.at(countryInd[i]) << "\t" << voteTotal[countryInd[i]] << endl; // only indirect access via countryInd