2
\$\begingroup\$

This is a school project and took me a while to write the code. Any help to improve my code is welcome!

#include <fstream>
#include <conio>
#include <stdio>
#include <stdlib>
#include <iomanip>
#include <windows>
#include <time>
typedef char string[50];
int ra;
/***************************************
Modified gets() function that limits character input
***************************************/
void mygets(char *s, int limit)
{
    void delchar(char*, int, int, int&);
   int i, curx, done;
   int col=wherex();
   for(i=0; i<limit; i++)
      cout<<' ';
   gotoxy(col, wherey());
   done=curx=i=0;
   do
   {
      char ch=char(getch());
      switch(ch)
      {
         case 0:
            ch=char(getch());
            switch (ch)
            {
               case 75:
                  if (curx>0)
                  {
                     curx--;
                     gotoxy(wherex()-1, wherey());
                  }
                  break;
               case 77:
                  if (curx<i)
                  {
                     curx++;
                     gotoxy(wherex()+1, wherey());
                  }
                  break;
               case 83:
                  if (i>0)
                  {
                     if (curx<i)
                     {
                        delchar(s, col, curx+1, i);
                        gotoxy(col+curx, wherey());
                        if (i==0)
                           s[i]=0;
                     }
                  }
            }
            break;
         case 8:
            if (curx>0)
            {
               delchar(s, col, curx, i);
               gotoxy(col+curx-1, wherey());
               curx--;
               if (i==0)
                  s[i]=0;
            }
            break;
         case 13:
            done=1;
            s[i]=0;
            break;
         case 27:
            done=1;
            s[0]=0;
            break;
         default:
            if (i<limit)
            {
               if (curx<i)
               {
                  s[curx]=ch;
                  cout<<ch;
                  curx++;
               }
               else
               {
                  s[i]=ch;
                  cout<<ch;
                  i++;
                  curx=i;
               }
            }
            else
               s[i]=0;
      }
   }
   while(!done);
   cout<<endl;
}
/*********************************************
Function to delete character
*********************************************/
void delchar(char *s, int col, int p, int &len)
{
   int i;
   for(i=p; i<len; i++)
      s[i-1]=s[i];
   gotoxy(col+p-1, wherey());
   len--;
   for(i=p-1; i<len; i++)
      cout<<s[i];
   cout<<' ';
}

/***************************************
Player class declaration
***************************************/
class player
{
    int sec , lives;
   string name;
   char difficulty[7];
   public:
    char *retname(){return name;}
      char *retdifficulty(){return difficulty;}
        int rettime(){return sec;}
        int retlives(){return lives;}
      char *setdifficulty(char *d){strcpy(difficulty,d);}
        int setlives(int l){lives=l;}
      int settime (int s){sec=s;}
      void getname()
      {
        Sleep(2000);
            clrscr();
         cout<<"Welcome Player !\nEnter your name:";
         gets(name);
      }
}a;

/***************************************
Function displays welcome screen
***************************************/
void welcome()

{
    char letter;
    for (int intro_letter = 1 ; intro_letter<=7 ; intro_letter++)
   {
    switch (intro_letter)
      {
        case 1:
            letter = 'H';
            break;
         case 2:
            letter = 'A';
            break;
         case 3:
            letter = 'N';
            break;
         case 4:
            letter = 'G';
            break;
        case 5:
            letter = 'M';
            break;
         case 6:
            letter = 'A';
            break;
         case 7:
            letter = 'N';
            break;
      }
      for (int slider = 1 ; slider<=10 ; slider++)
      {
         gotoxy(35+intro_letter,slider);
        Sleep(50);
         if (slider==10)
            printf("%c",letter);
      }
   }
   Sleep(60);
   cout<<"\n\n\n                               By: Mohit Bhasi";
}
/*************************************
Function to display levels
**************************************/
void displaylvl()
{
    clrscr();
    system("color f3");
    char d[2];
   while (true)
   {
    cout<<"Levels:\n\n";
    cout<<"1.Easy\n";
    cout<<"2.Medium\n";
    cout<<"3.Hard\n";
        cout<<"Choose your difficulty:";
    mygets(d,1);
       if (d[0]=='1')
    {
        a.setdifficulty("Easy");
        break;
      }
    else
    if (d[0]=='2')
      {
        a.setdifficulty("Medium");
        break;
      }
    else
        if (d[0]=='3')
      {
        a.setdifficulty("Hard");
        break;
      }
    else
        {
            gotoxy(0,2);
        cout<<"Enter 1 , 2 or 3 only!\n";
         Sleep(1200);
           clrscr();
        }
   }
}
int gen()
{
    randomize();
   int j = random(10);
   int a[]={0,2,4,6,8,10,12,14,16,18};
   return a[j];
}
/***********************************************
Function to get a word from file
***********************************************/
char *getword()
{
   int j = gen();
   string word;
   string wordlist[20];
   if (strcmpi(a.retdifficulty(),"easy")==0)
   {
      int x = 0;
      ifstream fin("easy.txt");
      while (fin>>word)
      {
         strcpy(wordlist[x],word);
         x++;
      }
      return wordlist[j];
   }
   if (strcmpi(a.retdifficulty(),"medium")==0)
   {
      int x = 0;
      ifstream fin2("medium.txt");
      while (fin2>>word)
      {
        strcpy(wordlist[x],word);
         x++;
      }
      return wordlist[j];
   }
   if (strcmpi(a.retdifficulty(),"hard")==0)
   {
      int x = 0;
      ifstream fin3("hard.txt");
      while (fin3>>word)
      {
         strcpy(wordlist[x],word);
         x++;
      }
      return wordlist[j];
   }
}
/*****************************************
Linear search function
******************************************/
int search(char a,char *b,int &pos)
{
    int x = 0;
   for (int j = 0 ; b[j] ; j++)
    if (a==b[j])
      {
        x++;
        pos=j;
    }
   return x;
}
int search(char a,char *b)
{
    int x = 0;
   for (int j = 0 ; b[j] ; b++)
    if (a==b[j])
        x++;
   return x;
}

/***********************************
Function to draw letters in place
***********************************/
void draw (char guess[],int xc)
{

    if (guess[0]=='a')
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "|   |";
    gotoxy((xc*6)+3,17);
      cout << "|___|";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "|   |";
   }
   if (guess[0]=='b')
    {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "|   \\";
    gotoxy((xc*6)+3,17);
      cout << "|___/";
      gotoxy((xc*6)+3,18);
      cout << "|   \\";
      gotoxy((xc*6)+3,19);
      cout << "|___/";
   }
   if (guess[0]=='c')
    {

        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "/   \\";
    gotoxy((xc*6)+3,17);
      cout << "|";
      gotoxy((xc*6)+3,18);
      cout << "|";
      gotoxy((xc*6)+3,19);
      cout << "\\___/";
   }
   if (guess[0]=='d')
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "|   \\";
    gotoxy((xc*6)+3,17);
      cout << "|   |";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "|___/";
   }
   if (guess[0]=='e')
   {
        gotoxy((xc*6)+3,15);
      cout << " ____";
    gotoxy((xc*6)+3,16);
      cout << "|";
    gotoxy((xc*6)+3,17);
      cout << "|____";
      gotoxy((xc*6)+3,18);
      cout << "|";
      gotoxy((xc*6)+3,19);
      cout << "|____";
   }
   if (guess[0]=='f')
   {
        gotoxy((xc*6)+3,15);
      cout << " ____";
    gotoxy((xc*6)+3,16);
      cout << "|";
    gotoxy((xc*6)+3,17);
      cout << "|____";
      gotoxy((xc*6)+3,18);
      cout << "|";
      gotoxy((xc*6)+3,19);
      cout << "|";
   }
   if (guess[0]=='g')
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "/   \\";
    gotoxy((xc*6)+3,17);
      cout << "|  __";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "\\___/";
   }
   if (guess[0]=='h')
   {
        gotoxy((xc*6)+3,15);
      cout << "|   |";
    gotoxy((xc*6)+3,16);
      cout << "|   |";
    gotoxy((xc*6)+3,17);
      cout << "|___|";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "|   |";
   }
   if (guess[0]=='i')
   {
        gotoxy((xc*6)+3,15);
      cout << "_____";
    gotoxy((xc*6)+3,16);
      cout << "  |";
    gotoxy((xc*6)+3,17);
      cout << "  |";
      gotoxy((xc*6)+3,18);
      cout << "  |";
      gotoxy((xc*6)+3,19);
      cout << "__|__";

   }
   if (guess[0]=='j')
   {
        gotoxy((xc*6)+3,15);
      cout << " ____";
    gotoxy((xc*6)+3,16);
      cout << "   | ";
    gotoxy((xc*6)+3,17);
      cout << "   | ";
      gotoxy((xc*6)+3,18);
      cout << "   | ";
      gotoxy((xc*6)+3,19);
      cout << "\\__/ ";
   }
   if (guess[0]=='k' )
   {
        gotoxy((xc*6)+3,15);
      cout << "|  /";
    gotoxy((xc*6)+3,16);
      cout << "| /";
    gotoxy((xc*6)+3,17);
      cout << "|/";
      gotoxy((xc*6)+3,18);
      cout << "| \\";
      gotoxy((xc*6)+3,19);
      cout << "|  \\";
   }
   if (guess[0]=='l' )
   {
        gotoxy((xc*6)+3,15);
      cout << "| ";
    gotoxy((xc*6)+3,16);
      cout << "| ";
    gotoxy((xc*6)+3,17);
      cout << "| ";
      gotoxy((xc*6)+3,18);
      cout << "| ";
      gotoxy((xc*6)+3,19);
      cout << "|____";

   }
   if (guess[0]=='m' )
   {
        gotoxy((xc*6)+3,15);
      cout << "      ";
    gotoxy((xc*6)+3,16);
      cout << "|\\ /|";
    gotoxy((xc*6)+3,17);
      cout << "| V |";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "|   |";
   }
   if (guess[0]=='n' )
   {
        gotoxy((xc*6)+3,15);
      cout << "    ";
    gotoxy((xc*6)+3,16);
      cout << "|\\  |";
    gotoxy((xc*6)+3,17);
      cout << "| \\ |";
      gotoxy((xc*6)+3,18);
      cout << "|  \\|";
      gotoxy((xc*6)+3,19);
      cout << "|   | ";

   }
   if (guess[0]=='o' )
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "/   \\";
    gotoxy((xc*6)+3,17);
      cout << "|   |";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "\\___/";
   }
   if (guess[0]=='p' )
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "|   \\";
    gotoxy((xc*6)+3,17);
      cout << "|___/";
      gotoxy((xc*6)+3,18);
      cout << "|";
      gotoxy((xc*6)+3,19);
      cout << "|    ";
   }
   if (guess[0]=='q' )
   {
        gotoxy((xc*6)+3,15);
      cout << " __";
    gotoxy((xc*6)+3,16);
      cout << "/  \\";
    gotoxy((xc*6)+3,17);
      cout << "|  |";
      gotoxy((xc*6)+3,18);
      cout << "|  |";
      gotoxy((xc*6)+3,19);
      cout << "\\__\\    ";
   }
   if (guess[0]=='r' )
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "|   \\";
    gotoxy((xc*6)+3,17);
      cout << "|___/";
      gotoxy((xc*6)+3,18);
      cout << "|  \\";
      gotoxy((xc*6)+3,19);
      cout << "|   \\";
   }
   if (guess[0]=='s' )
   {
        gotoxy((xc*6)+3,15);
      cout << " ___";
    gotoxy((xc*6)+3,16);
      cout << "/   \\";
    gotoxy((xc*6)+3,17);
      cout << "\\___";
      gotoxy((xc*6)+3,18);
      cout << "    \\";
      gotoxy((xc*6)+3,19);
      cout << "\\___/";
    }
   if (guess[0]=='t' )
   {
        gotoxy((xc*6)+3,15);
      cout << "_____";
    gotoxy((xc*6)+3,16);
      cout << "  |";
    gotoxy((xc*6)+3,17);
      cout << "  |";
      gotoxy((xc*6)+3,18);
      cout << "  |";
      gotoxy((xc*6)+3,19);
      cout << "  |  ";
   }
   if (guess[0]=='u' )
   {
        gotoxy((xc*6)+3,15);
      cout << "|   |";
    gotoxy((xc*6)+3,16);
      cout << "|   |";
    gotoxy((xc*6)+3,17);
      cout << "|   |";
      gotoxy((xc*6)+3,18);
      cout << "|   |";
      gotoxy((xc*6)+3,19);
      cout << "\\___/";
   }
   if (guess[0]=='v' )
   {
        gotoxy((xc*6)+3,15);
      cout <<"      ";
    gotoxy((xc*6)+3,16);
      cout <<"      ";
    gotoxy((xc*6)+3,17);
      cout <<"\\    /";
      gotoxy((xc*6)+3,18);
      cout <<" \\  /";
      gotoxy((xc*6)+3,19);
    cout <<"  \\/ ";
   }
   if (guess[0]=='w' )
   {
        gotoxy((xc*6)+3,18);
      cout <<"\\   /";
    gotoxy((xc*6)+3,19);
      cout << " \\|/ ";
   }
   if (guess[0]=='x' )
   {
        gotoxy((xc*6)+3,15);
      cout << "\\   /";
    gotoxy((xc*6)+3,16);
      cout << " \\ /";
    gotoxy((xc*6)+3,17);
      cout << "  /";
      gotoxy((xc*6)+3,18);
      cout << " / \\";
      gotoxy((xc*6)+3,19);
      cout << "/   \\";
   }
   if (guess[0]=='y' )
   {
        gotoxy((xc*6)+3,15);
      cout << "\\   /";
    gotoxy((xc*6)+3,16);
      cout << " \\ /";
    gotoxy((xc*6)+3,17);
      cout << "  |";
      gotoxy((xc*6)+3,18);
      cout << "  |";
      gotoxy((xc*6)+3,19);
      cout << "  |  ";
   }
   if (guess[0]=='z' )
   {
        gotoxy((xc*6)+3,15);
      cout << "_____";
    gotoxy((xc*6)+3,16);
      cout << "    /";
    gotoxy((xc*6)+3,17);
      cout << "   / ";
      gotoxy((xc*6)+3,18);
      cout << " /   ";
      gotoxy((xc*6)+3,19);
      cout << "/____";
   }
}
/*****************************************
Draw hangman
******************************************/
void drawman (int part)
{
    if (part==9)
   {
      for (int i = 52 ; i<=58 ; i++)
      {
        gotoxy(i,22);
         cout<<"_";
      }
   }
    if (part==8)
   {
      for (int i = 4 ; i<=22 ; i++)
      {
        gotoxy(55,i);
         cout<<"|";
      }
   }
    if (part==7)
   {
    gotoxy(55,4);
      cout<<"______________";
   }
   if (part==6)
   {
    gotoxy(68,5);
      cout << "|";
      gotoxy(68,6);
      cout << "|";
   }
    if (part==5)
   {
        gotoxy(60,7);
      cout << "      /   /";
      gotoxy(60,8);
      cout << "   /         /";
      gotoxy(60,9);
      cout << "  /           /";
      gotoxy(60,10);
      cout << "  /           /";
      gotoxy(60,11);
      cout << "   /         /";
      gotoxy(60,12);
      cout << "      /   /";
   }
   if (part==4)
   {
    for(int k=0;k<7;k++)
      {
        gotoxy(68,13+k);
         cout << "|";
      }
   }
   if (part==3)
   {
        gotoxy(65,14);
        cout << "\\";
      gotoxy(66,15);
      cout << "\\";
      gotoxy(67,16);
      cout << "\\";
   }
   if (part==2)
   {
    gotoxy(71,14);
      cout << "/";
      gotoxy(70,15);
      cout << "/";
      gotoxy(69,16);
      cout << "/";
   }
   if (part==1)
   {
    gotoxy(67,20);
      cout << "/";
      gotoxy(66,21);
      cout << "/";
      gotoxy(65,22);
      cout << "/";
   }
   if (part==0)
   {
    gotoxy(69,20);
      cout << "\\";
      gotoxy(70,21);
      cout << "\\";
      gotoxy(71,22);
      cout << "\\";
   }
}
/******************************************
Display dashes
*******************************************/
void dash(int n)
{
    gotoxy(3,20);
    for (int x = 1 ; x<=n ; x++)
    cout<<"_____ ";
}
/*****************************************
Function to check if letter is a vowel
******************************************/
int isvowel(char c)
{
    if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
    return 1;
   else
    return 0;
}
/******************************************
Function for the game
*******************************************/
void gamedisplay()
{
    clrscr();
    system("color f3");
    char guess[100];
   string clue,word;
   int lives = 10, right = 0;
   strcpy(word,getword());
   dash(strlen(word));
   gotoxy(1,1);
   printf("Try guessing your word %s ! , Good Luck %c :\n",a.retname(),char(1));
   printf("Clue : %s \n" , clue);
   time_t start = time(NULL);
   int x = 0;
   while (lives!=0 && right!=strlen(word))
   {
    gotoxy(1,3);
      clreol();
      char check[100];
      while (true)
      {
        gotoxy(1,3);
        clreol();
        cout<<"Enter your guess:";
        mygets(guess,1);
        check[x]=guess[0];
         x++;
         if (search(guess[0],check)>1)
            cout<<"Entered before !\n";
         else
            break;
      }
      if (search(guess[0],word) > 0)
      {
        if (search(guess[0],word) == 1)
         {
            if (isvowel(guess[0]))
                cout<<"There is an "<<guess[0]<<"   "<<endl;
            else
                cout<<"There is a  "<<guess[0]<<"   "<<endl;
         }
         if (search(guess[0],word) > 1)
            cout<<"There are "<<search(guess[0],word)<<" "<<guess[0]<<" 's\n";
         right+=search(guess[0],word);
            int xc=0 ;
        search(guess[0],word,xc);
         /*
         If there appears more than one occurence of the letter
         the search will find position of last occurence of the letter.
         Hence find the occurence and simultaneously display it on the screen!
         */
         if (search(guess[0],word) > 1)
         {
            for (int k = 0 ; word[k] ; k++)
            {
                if (guess[0]==word[k])
                xc = k;
                gotoxy((xc*5)+2,15);
               draw(guess,xc);  //handles more than one occurence of a letter
            }
         }
         draw(guess,xc);  //handles one occurence of a letter
         gotoxy(1,3);
         cout<<"\n\nLetters remaining:"<<(strlen(word)-right);
      }
      else
      {
        cout<<"Sorry,try again! \n\nLives remaining:"<<--lives<<endl;
         drawman(lives);
      }
   }
   time_t end = time(NULL) - start;
   cout<<endl;
    if (lives == 0)
   {
    cout<<"Sorry :( game over!\n";
      printf("The word was : %s \n", word);
      a.setlives(0);
   }
   else
   {
    cout<<"Congratulations  !\n";
    cout<<"\nTime taken:"<<end<<"s";
      a.setlives(lives);
   }
   a.settime(end);
}
/*********************************************
Write player info into file
*********************************************/
void write()
{
    ofstream fout;
   fout.open("game.txt" , ios::app);
   fout<<"Name:"<<a.retname()<<endl;
   fout<<"Difficulty:"<<a.retdifficulty()<<endl;
   fout<<"Lives left:"<<a.retlives()<<endl;
   fout<<"Time taken:"<<a.rettime()<<" s"<<endl<<endl;
}
/*********************************************
Main function
*********************************************/
void main()
{

    system("color f3");
    welcome();
   a.getname();
   displaylvl();
   gamedisplay();
   if (a.retlives()!=0)
    write();
    getch();
}
\$\endgroup\$
  • 1
    \$\begingroup\$ What is gotoxy ? \$\endgroup\$ – Caridorc Aug 27 '15 at 18:14
  • \$\begingroup\$ gotoxy moves the cursor at the given xy coordinates \$\endgroup\$ – Caridorc Aug 28 '15 at 7:52
4
\$\begingroup\$

Data oriented programming

The following block of code is repated with little differences 26 times:

    if (guess[0]=='a')
   {
    gotoxy((xc*6)+3,15);
  cout << " ___";
gotoxy((xc*6)+3,16);
  cout << "|   |";
gotoxy((xc*6)+3,17);
  cout << "|___|";
  gotoxy((xc*6)+3,18);
  cout << "|   |";
  gotoxy((xc*6)+3,19);
  cout << "|   |";

To print all the letters. I suggest loading the ascii art from a file, as code and resources (ascii art in this case) should be separated.

The same can be said about:

void drawman (int part)

Instead of generating the lines looping (that is of dubious utility) just load a file, split it in 9 pieces and display hangman_pieces[part] when the function is called.

isvowel

You should return bool rather than int, the former expresses your logic better than the latter, also if cond return true else return false can be replaced with return cond, so

bool isvowel(char c)
{
    return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}

Braces

if (a.retlives()!=0)
    write();
    getch();

Is getch inside or outside the conditional branch? Put braces where needed to include or exclude it. Braces should always be included to avoid ambiguity.

Indentation

You should use an automatic tool to indent (put spaces before lines at branches) your code, it costs little effort and improves readibility.

search

You have to very similar (equal?) Versions of the same function:

 int search(char a,char *b,int &pos)
{
    int x = 0;
   for (int j = 0 ; b[j] ; j++)
    if (a==b[j])
      {
        x++;
       pos=j;
      }
   return x;
 }

 int search(char a,char *b)
{
     int x = 0;
   for (int j = 0 ; b[j] ; b++)
      if (a==b[j])
         x++;
   return x;
}

You need neither as you can just use the built-in index.

delchar

void delchar(char *s, int col, int p, int &len)
{
   int i;
   for(i=p; i<len; i++)
      s[i-1]=s[i];
   gotoxy(col+p-1, wherey());
   len--;
   for(i=p-1; i<len; i++)
      cout<<s[i];
   cout<<' ';
}

Minor things:

  • Braces
  • Remove len-- and use len - 1 in the loop.
  • Declare i inside the loop.

But if I understand correctly, this function both deletes a char AND overwrites it with another string. It should do only one thing.

\$\endgroup\$
2
\$\begingroup\$

One of the things I would look at is clarifying your function names and class names. For example

using namespace std;
class Name
{
    public:
        //The first letter in each word is capitalized for ease of reading
        void AnotherClassName();
        string *ClassWithStringReturn(const string& item);
    private:
        //variables should always have a lower case letter, this helps
        //readablity and should have a under bar before or after the 
        //variable name so people can tell its a private member variable
        string valueName_;
        char letterName_;
}

This is much easier to read, and when you get higher up in the programming classes, teachers and peers would like to see this type of naming scheme more. It's best to get in the practice now, so it's not a change later on. Some teachers including my own prefer single returns. I know that is not always the case, but that helps a lot in debug. Overall your code is good! Other then the formatting, which isn't a big deal till later, you seem to be using everything like you should. In my opinion it is easier to code later on, because you get to use headers and source files, and STL more. But Overall you are doing good. I would take some time and maybe add some comments around your loop statements and switch statements to help the teacher, and yourself later, to figure out what's going on faster. Some times you can find a good bit of errors just by reading what you want to happen and seeing what the code is actually doing.

I hope this helps, but for the most part your code is good especially if you are starting out. So all I can really do is just tell you a good format to take for coding guidelines.

\$\endgroup\$
  • \$\begingroup\$ Welcome to CodeReview! (I am kind of scared that this is good C++, it looks so long and complex for such a simpls task... maybe C++ is just this way...) \$\endgroup\$ – Caridorc Aug 27 '15 at 20:11
  • \$\begingroup\$ No, I believe he is starting out. I remember my entry level classes, they had me doing everything "the long way". That way when you got into STL, you knew what was going on in the back-end. Take strings for instance. Char [] is essentially a string, but just using string out the gate keeps a programmer from fully appreciating what people had to do before STL. The teachers wanted us to appreciate C++ by making us code like we were using C. So yes, Its very long, but he, I'm hoping, was probably instructed to do it that way. \$\endgroup\$ – Caperneoignis Sep 8 '15 at 16:42
  • \$\begingroup\$ And thank you for the welcome! Sorry for the delay, just saw that I had a chat waiting. \$\endgroup\$ – Caperneoignis Sep 8 '15 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.