I need to grab the stuff out of the input file store it in the array and then sort it alphabetically.
// CandyStore 11/06/2015
//This project will put name salphabetically on candy bins
#include <iostream>
#include <string>
#include <fstream>
#include <Windows.h>
#include <vector>
#include <algorithm>
using namespace std;
bool rainbow = false;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
const int delay = 10;
const int CANDY_BINS = 20;
string candyNames[20];
string alphaOrderArray[20];
string wallArray[5][4];
// declaring voids
void readAndSort();
void printArray();
void printArray(string list[], int listSize);
void Print(string s);
void whitePrint(string s);
void rainbowPrint(string s);
int main()
{
readAndSort();
}
void readAndSort()
{
ifstream myfile;
myfile.open("CandyStore.txt");
if (!myfile)
cout << "ERROR";
for (int i = 0; i < 20; i++)
{
getline(myfile, alphaOrderArray[i]);
}
printArray(alphaOrderArray, 20);
system("PAUSE");
}
void printArray(string list[], int listSize)
{
int index;
for (index = 0; index < listSize; index++)
{
rainbowPrint(list[index]);
cout << endl;
}
}
void Print(string s)
{
if (rainbow)
rainbowPrint(s);
else
whitePrint(s);
}
void whitePrint(string s)
{
int length = s.length();
for (int position = 0; position < length; position++)
{
Beep(1, delay);
cout << s.at(position);
}
}
void rainbowPrint(string s)
{
int colors[6] = { (FOREGROUND_RED | FOREGROUND_INTENSITY), (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY), (FOREGROUND_GREEN | FOREGROUND_INTENSITY), //R, RG, G,
(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY), (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY), (FOREGROUND_RED | FOREGROUND_INTENSITY) }; // BG, RB, R
int length = s.length();
int curColor = 0;
for (int position = 0; position < length; position++)
{
if (s.at(position) != ' ')
SetConsoleTextAttribute(hConsole, colors[curColor]);
Beep(1, delay);
cout << s.at(position);
if (s.at(position) != ' ')
{
curColor++;
if (curColor > 5)
{
curColor = 1;
SetConsoleTextAttribute(hConsole, (FOREGROUND_RED | FOREGROUND_INTENSITY));
}
}
}
SetConsoleTextAttribute(hConsole, (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY));
}
Last edited on