How does selection sort work? - c++

This is a selection sort that I'm trying and I don't understand why it isn't working. My understanding is that selection sort scans a vector for the smallest value which when it finds it moves it to the beginning of the vector. It preforms another scan this time ignoring the first element and doing it all over again until n - 1 times where n is the length of the vector.
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>
using namespace std;
int main()
{
vector <string> vName, vID, vClass;
string sName, minValue, sID, sClass, sSearch, sQuestion, ssSearch, sSearchN, sSearchI;
int iSize, iStudent;
// Display initial vector size
iSize = vName.size();
cout << "Student list starts with the size:" << iSize << endl;
// Get size of list from user
cout << "How many students would you like to add?" << endl;
cin >> iStudent;
cin.ignore();
// Get names, ids, and classes
for (int i = 0; i < iStudent; i++)
{
cout << "Student" << i + 1 << ":\n";
cout << "Please enter the student name: ";
getline(cin, sName);
vName.push_back(sName);
cout << "Enter ID number ";
getline(cin, sID);
vID.push_back(sID);
cout << "Enter class name ";
getline(cin, sClass);
vClass.push_back(sClass);
}
// Display header
cout << "The list of students has the size of: " << iStudent << endl;
cout << "The Student List" << endl;
cout << "\n";
cout << "Name:" << setw(30) << "ID:" << setw(38) << "Enrolled Class : " << endl;
cout << "--------------------------------------------------------------------------";
cout << "\n";
// for loop for displying list
for (int x = 0; x < vName.size() && vID.size() && vClass.size(); x++)
{
cout << vName[x] << "\t \t \t" << vID[x] << "\t \t \t" << vClass[x] << endl;
}
// Sorting function and for loop to display sorted names
cout << "\n";
cout << "The Student List after Sorting:" << endl;
cout << "\n";
//*************************************
int startScan, minIndex;
for (startScan = 0; startScan < vName.size() - 1; startScan++)
{
minIndex = startScan;
minValue = vName[startScan];
for (int index = startScan + 1; index < vName.size(); index++)
{
if (vName[index] < minValue)
{
minValue = vName[index];
minIndex = index;
}
}
vName[minIndex] = vName[startScan];
vName[startScan] = minValue;
vID[minIndex] = vID[startScan];
vID[startScan] = minValue;
vClass[minIndex] = vClass[startScan];
vClass[startScan] = minValue;
}
//******************
//sort(vName.begin(), vName.end());
//for (int y = 0; y < vName.size(); y++)
//{
// cout << vName[y] << endl;
//}
cout << "\n";
// Search function uses a do while loop that loops so long as the user inputs a "y" or "Y"
do
{
int iPick;
cout << "Search Menu:" << endl;
cout << "1. By Name\n";
cout << "2. By ID\n \n";
cin >> iPick;
if (iPick == 1)
{
cout << "Please Enter a name to be searched:" << endl;
getline(cin >> ws, sSearchN);
if (binary_search(vName.begin(), vName.end(), sSearchN))
{
cout << sSearchN << " was found." << endl << endl;
}
else
{
cout << sSearchN << " was not found." << endl << endl;
}
cout << "Would you like to search another name?" << endl << endl;
cout << vName[0];
cout << "Please enter Y for Yes and N for No:" << endl << endl;
getline(cin >> ws, sQuestion);
}
else
{
cout << "Please Enter an ID to be searched:" << endl;
getline(cin >> ws, sSearchI);
if (binary_search(vID.begin(), vID.end(), sSearchI))
{
cout << sSearchI << " " << "was found" << endl << endl;
cout << "Please enter Y for Yes and N for No:" << endl << endl;
getline(cin >> ws, sQuestion);
}
else
{
cout << sSearchI << " " << "was not found." << endl << endl;
cout << "Please enter Y for Yes and N for No:" << endl << endl;
getline(cin >> ws, sQuestion);
}
}
} while (sQuestion == "Y" || sQuestion == "y");
cout << "Thank you for using this program!" << endl;
return 0;
}
EDIT: posted whole program
So the issue is it doesn't sort at all, just gives back vName unsorted.

Okay upon more further study of the code I think I've figured it out.
So looking at the part of the code that is sorting, the way that it works is actually pretty simple. startScan is an int increments until it becomes equal to the size of the vector in the for loop. In this case it is vName. minIndex will hold the smallest index number which at the time of initialization will be equal to the starScan. Finally minValue is a string (in this case because we have a vector of strings) that acts as a temporary container for the element at vName[scanStart]. In the second for loop index will be incremented through the vector and will test if the element vName[index] is smaller than the temproray container i talked about earlier. If it is than the new temp will be vName[index] after that is done it will exit the inner loop and update and move on to the next smallest value in vName. Understanding this it's easy to make it so that the sorting happens with 2 other vectors. All one has to do is create containers for those vectors like the ones i have here minValueA and minValueB. They will simply be changing as vName changes. That way everything stays in the order in which vName is ordered. I hope that helps someone!
int startScan, minIndex;
string minValue, minValueA, minValueB;
for (startScan = 0; startScan < vName.size() - 1; startScan++)
{
minIndex = startScan;
minValue = vName[startScan];
minValueA = vID[startScan];
minValueB = vClass[startScan];
for (int index = startScan + 1; index < vName.size(); index++)
{
if (vName[index] < minValue)
{
minValue = vName[index];
minValueA = vID[index];
minValueB = vClass[index];
minIndex = index;
}
}
vName[minIndex] = vName[startScan];
vName[startScan] = minValue; //values for vName are being added to the other ones.
vID[minIndex] = vID[startScan];
vID[startScan] = minValueA;
vClass[minIndex] = vClass[startScan];
vClass[startScan] = minValueB;
}
//******************
sort(vName.begin(), vName.end());
for (int y = 0; y < vName.size(); y++)
{
cout << vName[y] << "\t \t \t " << vID[y] << "\t \t \t " << vClass[y] << endl;
}

Related

How do i add up my array values and display it along side with my other values

I am trying to add up all the values that have been stored into array b and have it display under the "total column" and don't know how to only have the scores add together.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int array[5][4];
int sum = 0;
cout<<"Enter grades for 4 exams for the 5 students \n";
for(int i=0;i<5;i++)
{
for(int b=1;b<=4;b++)
{
cout <<setw(8)<< "enter student "<< i << "'s grade for exam " << b << '\n';
cin >> array[i][b];
}
}
cout <<"ID"<<setw(11)<<"score 1"<<setw(11)<<"score 2"<<setw(11)<<"score 3"<<setw(11)<<"score 4"<<setw(11)<<"total"<<setw(11)<<"letter"<<endl;
cout <<"--------------------------------------------------------------------------------------------------------------\n";
for(int i=0;i<5;i++)
{
cout << i<< " ";
for(int b=1;b<=4;b++)
{
sum = sum + array[b];
cout <<setw(10)<<array[i][b]<<sum;
}
cout <<'\n';
}
cout <<"--------------------------------------------------------------------------------------------------------------\n";
return 0;
}
To be more specific around line 28
for(int i=0;i<5;i++)
{
cout << i<< " ";
for(int b=1;b<=4;b++)
{
sum = sum + array[b];
cout <<setw(10)<<array[i][b]<<sum;
}
cout <<'\n';
Arrays indexes start at 0, not 1. You are correctly looping through your array's 1st dimension, but not its 2nd dimension. You need to change the inner for loops from for(int b=1;b<=4;b++) to for(int b=0;b<4;b++)
Also, to handle the total column, you simply need to reset sum to 0 on each iteration of the 1st dimension, and then print the result after the iteration of the 2nd dimension.
Try this:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int array[5][4];
cout << "Enter grades for 4 exams for the 5 students \n";
for(int i = 0; i < 5; i++)
{
for(int b = 0; b < 4; b++)
{
cout << "Enter student " << i+1 << "'s grade for exam " << b+1 << '\n';
cin >> array[i][b];
}
}
cout << "ID" << setw(11) << "score 1" << setw(11) << "score 2" << setw(11) << "score 3" << setw(11) << "score 4" << setw(11) << "total" << setw(11) << "letter" << endl;
cout << "--------------------------------------------------------------------------------------------------------------\n";
for(int i = 0; i < 5; i++)
{
cout << setw(2) << left << i+1 << right;
int sum = 0;
for(int b = 0; b < 4; b++)
{
sum = sum + array[i][b];
cout << setw(11) << array[i][b];
}
cout << setw(11) << sum << '\n';
}
cout << "--------------------------------------------------------------------------------------------------------------\n";
return 0;
}
Online Demo

Adding all value to total in for loop

I'm new to coding. I wrote the below code in C++ and I am not allow to use array.
You will create a console C++ program that uses a nested loop to enter each archer's individual end scores and then displays the total score for each archer.
I am stuck at how to calculate the total end score:
#include <iomanip>
using namespace std;
int main()
{
int Rounds = 4;
int Archers = 3;
int endScore ;
int average;
for (int a = 1; a <= Archers ; a++)
{
cout << endl << "Number " << a << " score" << endl;
int tEndScore = 0 ;
for(int i=1; i <=Rounds ; i++)
{
cout << "Round " << i << " : " ;
cin >> endScore;
while(cin.fail())
{
cout << endl << "not enter an integer " << endl ;
cout << "Please enter an integer ";
cin >> endScore;
}
tEndScore += endScore;
}
cout << endl << "The total score for 4 ends of Archer Number " << a << " is " << tEndScore << endl;
average =(double) tEndScore/Rounds;
cout << setiosflags(ios::fixed) << setprecision(2) << endl << "The average score of 4 ends of Archer Number " << a << " is " << average << endl;
}
}
This is the result after running. It will only use the last value I entered as tEndScore:
You need to shift tEndScore =+ endScore; this line inside the second for loop as
for(int i=1; i <=Rounds ; i++)
{
...
...
tEndScore += endScore;
}
And it will be a good practice (And mandatory for your code...) to initialize the tEndScore for each player as
for (int a = 1; a <= Archers ; a++)
{
tEndScore = 0;
endScore = 0;
average = 0;
...
...
}
You need to replace totalEndScore to tEndScore and totalRounds to Rounds.

How can I Terminate Vector Input Using if statement in C++

Does anybody have a simple solution to terminate a for loop that inputs values for a vector when a specific value is placed into the vector, but does not store that specified value into the vector?
I have created a random number generator that creates "n" unique values for a vector of size "n". However, when I run my code, the word "done" pops up and the program crashes.
Here is the code:
int main()
{
int i = 0;
vector<int> playerIndex;
vector<int> randGenNum;
vector<string> players;
vector<string> team1;
vector<string> team2;
vector<string> team3;
vector<string> team4;
cout << "Welcome to the Team Selector. \n" << endl;
cout << "A random team of two will be generated for you all." << endl;
cout << "When you are finished entering player names, enter the word \"done\". " << endl;
cout << "Enter the name of the players: \n" << endl;
for(string name; cin >> name;){
players.push_back(name);
if(name == "done"){
players.erase(players.end() - 1);
break;
}else{
playerIndex.push_back(i);
i++;
}
}
cout << "\n";
cout << "Player names: \n";
for(int a=0; a < players.size(); a++){
cout << a + 1 << " - " << players[a] << endl;
}
srand(time(0));
int b =0;
int randNum;
while(b < players.size()){
randNum = 1 +(rand()%players.size());
if(find(randGenNum.begin(), randGenNum.end(), randNum)!= randGenNum.end()){
while(find(randGenNum.begin(), randGenNum.end(), randNum)!= randGenNum.end()){
randNum = 1 +(rand()%players.size());
}
randGenNum.push_back(randNum);
b++;
}else{
randGenNum.push_back(randNum);
b++;
}
}
cout << "\n" <<"This is a test" << endl;
for (int c=0; c < players.size(); c++){
cout << "Generated #: " << randGenNum[c] << endl;
}
int totalPlayers = players.size();
int firstPlayer = randGenNum[0];
int secondPlayer = randGenNum[1];
int thirdPlayer = randGenNum[2];
int fourthPlayer = randGenNum[3];
int fifthPlayer = randGenNum[4];
cout << "\n";
cout << "Team 1 is: " << players[firstPlayer] << " and "<< players[secondPlayer] << "\n" << endl;
cout << "Team 2 is: " << players[thirdPlayer] << " and " << players[fourthPlayer] << "\n" << endl;
return 0;
}
Problem
players.end() - 1 is not a valid iterator.
Solutions 1:
Check the item before adding it to the vector.
for(string name; cin >> name;) {
if(name != "done")
{
players.push_back(name);
playerIndex.push_back(i);
i++;
}
}
Solutions 2:
Use std::vector::pop_back().
for(string name; cin >> name;){
players.push_back(name);
if(name == "done"){
players.pop_back();
break;
}else{
playerIndex.push_back(i);
i++;
}
}

how to call functions and unused expression error

I get an error saying: use of undeclared identifier 'again'.
I am trying to go from int main to void again and back after getting an answer.
Please explain to me why it won't work also. Thanks.
Here is my full code:
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
{
string answer;
cout << "Would you like to enter another set of data? Y or N?" << endl;
cin << answer;
string yes = "Yes";
string no = "No";
if(a == yes)
{
main();
}
}
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 11 - Vectors" << endl;
cout << "November 12, 2016" <<endl;
cout << endl;
cout << endl;
int size;
cout << " How many numbers would you like the vector to hold? " << endl;
cin >> size;
vector<int> numbers;
int bnumbers;
for (int count = 0; count < size; count++)
{
cout << "Enter a number: " << endl;
cin >> bnumbers;
numbers.push_back(bnumbers); // Adds an element to numbers
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int bcount = 0; bcount < size; bcount++)
{
cout << numbers[bcount] << " ";
}
cout << endl;
//display the numbers stored reversed
cout << "Here are the numbers in reverse order: " << endl;
reverse(numbers.begin(), numbers.end());
for(int rcount = 0; rcount < size; rcount++)
{
cout << numbers[rcount] << " ";
}
cout << endl;
again();
return 0;
}
void again()
}
You need to declare your fonction "again" before calling it :
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <string>
using namespace std;
void again();
int main()
{
cout << "Kaitlin Stevers" << endl;
cout << "Exercise 11 - Vectors" << endl;
cout << "November 12, 2016" <<endl;
cout << endl;
cout << endl;
int size;
cout << " How many numbers would you like the vector to hold? " << endl;
cin >> size;
vector<int> numbers;
int bnumbers;
for (int count = 0; count < size; count++)
{
cout << "Enter a number: " << endl;
cin >> bnumbers;
numbers.push_back(bnumbers); // Adds an element to numbers
}
//display the numbers stored in order
cout << "The numbers in order are: " << endl;
for(int bcount = 0; bcount < size; bcount++)
{
cout << numbers[bcount] << " ";
}
cout << endl;
//display the numbers stored reversed
cout << "Here are the numbers in reverse order: " << endl;
reverse(numbers.begin(), numbers.end());
for(int rcount = 0; rcount < size; rcount++)
{
cout << numbers[rcount] << " ";
}
cout << endl;
again();
return 0;
}
void again()
{
string answer;
cout << "Would you like to enter another set of data? Y or N?" << endl;
cin >> answer;
string yes = "Yes";
string no = "No";
if(answer == yes)
{
main();
}
}
However, it's a strange things to use recursivity for what you want to do and to call main func multiple times (which is by definition, main entry of a program). In my opinion, you should call in your main function another function named like askInformation which uses a loop with a test case to know if user wants to add informations or not.

Array of Structures - Functions not pulling through data

I am studying BscCS so I am familiar with programming concepts, however I always seem to get stuck on structs and arrays of structs.
I am required to convert parallel arrays into an array of structs. I have done this, but for some reason the information is not getting sent to the functions properly and the program keeps crashing.
Could you help identify where I am going wrong of if there is something I am missing? I don't need exact code for answers, just some guidance. Here is the code:
#define SIZE 3
struct Employee {
string firstName[SIZE];
string lastName[SIZE];
int id[SIZE];
int hoursWorked[SIZE];
int payRate[SIZE];
int stat[SIZE];
};
//Functions
int menu();
void printReport(Employee & employees);
void search(Employee & employees);
void calculatePay(Employee & employees);
void orderByLastName(Employee & employees);
void orderByid(Employee & employees);
void printActive(Employee & employees);
void printInactive(Employee & employees);
//Display Main Menu
int menu()
{
int choice;
cout << "1. Print out Employee Report. " << endl;
cout << "2. Search Employee Records. " << endl;
cout << "3. Display the Report in Sorted order on Last Name or ID. << endl;
cout << "4. Calculate Pay. " << endl;
cout << "5. Display Active Employees." << endl;
cout << "6. Display Inactive Employees." << endl;
cout << "7. Quit" << endl;
cout << "Enter your choice. ";
cin >> choice;
return choice;
}
//Display the employee data in a formatted order
void printReport(Employee & employees)
{
cout << setw(10) << "First Name" <<
setw(10) << "Last Name" <<
setw(10) << "ID" <<
setw(10) << "Hours" <<
setw(10) << "Rate" <<
endl;
ios::fixed;
for (int index = 0; index < SIZE; index++)
cout << setw(10) << employees.firstName[index] <<
setw(10) << employees.lastName[index] <<
setw(10) << employees.id[index] <<
setw(10) << employees.hoursWorked[index] <<
setw(10) << employees.payRate[index] << endl;
}
//Search for employee ID
//Show "Not Found" if unable to locate
void search(Employee & employees)
{
bool found = false;
int idNumber;
int pos = -1;
cout << "Enter id number ";
cin >> idNumber;
for (int index = 0; index < SIZE && !found; index++)
{
if (employees.id[index] == idNumber)
{
found = true;
pos = index;
}
}
if (!found)
cout << "Not Found. " << endl;
else
cout << setw(10) << employees.firstName[pos] <<
setw(10) << employees.lastName[pos] <<
setw(10) << employees.id[pos] <<
setw(10) << employees.hoursWorked[pos] <<
setw(10) << employees.payRate[pos] << endl;
}
//Calculate total weekly pay
void calculatePay(Employee & employees)
{
cout << setw(10) << "First Name" <<
setw(10) << "Last Name" <<
setw(10) << "ID" <<
setw(10) << "Hours" <<
setw(10) << "Rate" <<
setw(10) << "Total Pay" <<
endl;
ios::fixed;
for (int index = 0; index < SIZE; index++)
cout << setw(10) << employees.firstName[index] <<
setw(10) << employees.lastName[index] <<
setw(10) << employees.id[index] <<
setw(10) << employees.hoursWorked[index] <<
setw(10) << employees.payRate[index] <<
setw(10) << employees.hoursWorked[index] * employees.payRate[index] << endl;
}
//Sort employee data by last name
void orderByLastName(Employee & employees)
{
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE - 1; j++)
{
if (employees.lastName[j] > employees.lastName[j + 1])
{
string temp = employees.lastName[j];
employees.lastName[j] = employees.lastName[j + 1];
employees.lastName[j + 1] = temp;
temp = employees.firstName[j];
employees.firstName[j] = employees.firstName[j + 1];
employees.firstName[j + 1] = temp;
int tempid = employees.id[j];
employees.id[j] = employees.id[j + 1];
employees.id[j + 1] = tempid;
int temphours = employees.hoursWorked[j];
employees.hoursWorked[j] = employees.hoursWorked[j + 1];
employees.hoursWorked[j + 1] = temphours;
int temppayrate = employees.payRate[j];
employees.payRate[j] = employees.payRate[j + 1];
employees.payRate[j + 1] = temppayrate;
}
}
}
}
//Sort employee data by ID
void orderByid(Employee & employees)
{
for (int i = 0; i < SIZE; i++)
{
for (int j = 0; j < SIZE - 1; j++)
{
if (employees.id[j] > employees.id[j + 1])
{
string temp = employees.lastName[j];
employees.lastName[j] = employees.lastName[j + 1];
employees.lastName[j + 1] = temp;
temp = employees.firstName[j];
employees.firstName[j] = employees.firstName[j + 1];
employees.firstName[j + 1] = temp;
int tempid = employees.id[j];
employees.id[j] = employees.id[j + 1];
employees.id[j + 1] = tempid;
int temphours = employees.hoursWorked[j];
employees.hoursWorked[j] = employees.hoursWorked[j + 1];
employees.hoursWorked[j + 1] = temphours;
int temppayrate = employees.payRate[j];
employees.payRate[j] = employees.payRate[j + 1];
employees.payRate[j + 1] = temppayrate;
}
}
}
}
void printActive(Employee & employees)
{
bool found = false;
int pos = -1;
for (int index = 0; index < SIZE && !found; index++)
{
if (employees.stat[index] == 1)
{
found = true;
pos = index;
}
if (!found) {
cout << "No active employees." << endl;
}
else {
cout << setw(10) << employees.firstName[pos] <<
setw(10) << employees.lastName[pos] <<
setw(10) << employees.id[pos] <<
setw(10) << employees.hoursWorked[pos] <<
setw(10) << employees.payRate[pos] << endl;
}
}
}
void printInactive(Employee & employees)
{
bool found = false;
int pos = -1;
for (int index = 0; index < SIZE && !found; index++)
{
if (employees.stat[index] == 0)
{
found = true;
pos = index;
}
if (!found) {
cout << "No inactive employees." << endl;
}
else {
cout << setw(10) << employees.firstName[pos] <<
setw(10) << employees.lastName[pos] <<
setw(10) << employees.id[pos] <<
setw(10) << employees.hoursWorked[pos] <<
setw(10) << employees.payRate[pos] << endl;
}
}
}
int main()
{
struct Employee employees[SIZE];
//Read first and last name from user
for (int index = 0; index < SIZE; index++)
{
cout << "Enter first name : ";
cin >> employees[index].firstName[index];
cout << "Enter last name : ";
cin >> employees[index].lastName[index];
//Read ID, hours, and pay rate from user
while (employees[index].id[index] < 0)
{
cout << "Enter id : ";
cin >> employees[index].id[index];
if (employees[index].id[index] < 0)
{
cout << "Invalid Id number. " << endl;
cout << "Enter id : ";
cin >> employees[index].id[index];
}
}
while (employees[index].hoursWorked[index] < 0)
{
cout << "Enter hours worked : ";
cin >> employees[index].hoursWorked[index];
if (employees[index].hoursWorked[index] < 0)
{
cout << "Invalid hours. " << endl;
cout << "Enter hours worked : ";
cin >> employees[index].hoursWorked[index];
}
}
while (employees[index].payRate[index] < 0)
{
cout << "Enter Pay Rate : ";
cin >> employees[index].payRate[index];
if (employees[index].payRate[index] < 0)
{
cout << "Invalid pay rate. " << endl;
cout << "Enter Pay Rate : ";
cin >> employees[index].payRate[index];
}
}
while (employees[index].stat[index] < 0)
{
cout << "Enter your status. (0 - Inactive, 1 - Active) : ";
cin >> employees[index].stat[index];
if (employees[index].stat[index] < 0)
{
cout << "Enter your status : ";
cin >> employees[index].stat[index];
}
cout << endl;
}
}
//Loop to display menu options until user quits program
while (true)
{
//Call menu with options
int ch = menu();
//Different options to choose
switch (ch)
{
case 1:
printReport(employees[SIZE]);
break;
case 2:
search(employees[SIZE]);
break;
case 3:
int sortType;
cout << "1.Sort by Last Name." << endl;
cout << "2.Sort by ID." << endl;
cout << "Enter your choice. ";
cin >> sortType;
if (sortType == 1)
orderByLastName(employees[SIZE]);
else if (sortType ==2)
orderByid(employees[SIZE]);
break;
case 4:
calculatePay(employees[SIZE]);
break;
case 5: printActive(employees[SIZE]);
case 6: printInactive(employees[SIZE]);
break;
case 7:
exit(0);
}
}
system("pause");
return 0;
}
Thank you in advance!
I ran your program, and I received more than 20 errors before the compiler involuntarily stopped trying to compile any longer. All of them are connected to the lines of code using cout, cin, string, and setw. You need to use these keywords with the std namespace to fix this, and you need to include the iostream header file (#include <iostream>). Either you can write std:: in front of all of these keywords (i.e. std::cout) or you can declare the namespace in the preprocessor (using namespace std;). Also, for std::setw, you need to include the iomanip header file (#include <iomanip>). After that, you're missing a quotation in the menu function and a bracket at the end of the main function. (There's also a couple of problems with initializing the size of the struct members in the declaration, but I'll leave that up to you.) Hope this helped!