Hey, I'm somewhat new to programming in c++ and I have had this code I wrote for a long time now. I wrote this about 9 months ago when I was really interested in learning the c++ language but lost interest during the summer. Well, now I'm getting back into it and I would like to know what you think of this code. Its a simple guessing game and its pretty novice. What I would like to know is what you think of it; is there room for improvement? Is it sloppy? Am I not fully utilizing what c++ has to offer? Just tell me what you think.
/*
Guessing Game
By Jacob
*/
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <string.h>
#include <fstream>
#include <windows.h>
#include <STDLIB.H>
#include <conio.h>
#include "pause.h"
#include "clrscr.h"
using namespace std;
int main(void)
{
SetConsoleTitle( "Guessing Game By Jacob" );
int number;
int guess;
int i=0;
int x=8;
int intro;
double diff;
char name[256];
char choice[10];
srand(time(0));
number=rand()%100+1;
time_t start,end;
cout<<"MENU"<<endl;
cout<<"------------------------------------------------------------"<<endl;
cout<<"Type the number that corresponds with an available option."<<endl;
cout<<"------------------------------------------------------------"<<endl;
cout<<"1)Play Game"<<endl; cout<<"2)Restart Score"<<endl; cout<<"3)Exit"<<endl;
cin>>intro;
if(intro==3)
{ EXIT_SUCCESS; }
else if(intro==2)
{
cls();
ofstream score("score.txt", ios::trunc);
cout<<"Score list reset."<<endl;
cout<<"Press any key to continue. . ."<<endl;
getch();
cls();
return main();
}
else if(intro==1)
{
cls();
time (&start);
while (guess!=number)
{
cout<<""<<x<<" more tries"<<endl;
cout<<"Pick a number:"<<endl<<endl;
cin>>guess;
cin.ignore();
if(x==0)
{
time(&end);
cls();
cout<<"You are out of turns. The correct number was "<<number<<"."<<endl;
cout<<"Would you like to restart? (Y/N)"<<endl;
cin.getline(choice,10);
for(int y=0; y!=1;)
{
if(strcmp(choice, "y")==0)
{
cls();
return main();
y++;
}
if(strcmp(choice, "n")==0)
{ return 0; }
else
{ cin.getline(choice, 10); continue; }
}
}
if(guess<number)
{
cls();
cout<<"Too low!"<<endl<<endl;
x--;
i++;
}
else if(guess>number)
{
cls();
cout<<"Too high!"<<endl<<endl;
x--;
i++;
}
else
{
time(&end);
diff=difftime(end,start);
i++;
float math=diff/i*1000;
cout<<"Good job, you guessed the correct number!"<<endl<<endl;
ofstream score("score.txt", ios::app);
cout<<"You scored "<<math<<" points. Please enter your name so I can save your score:"<<endl;
cin.getline(name,256);
cls();
score<<""<<name<<" scored "<<math<<" points."<<endl;
cout<<"Check the score.txt file to see how you did."<<endl<<endl;
cout<<"Would you like to restart? (Y/N)"<<endl;
cin.getline(choice,10);
for(int z=0; z!=1;)
{
if(strcmp(choice, "y")==0)
{
cls();
return main();
z++;
}
if(strcmp(choice, "n")==0)
{ return 0; }
else
{ cin.getline(choice, 10); continue; }
}
}
}
}
else
{ cls(); return main(); }
}
Sorry for the 145 lines, lol.