I got the timer working and this is the program so far. I'm pretty happy with how it's turning out.
Code:
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <stdio.h>
//function prototypes
void starttest();
bool askquestion();
int length(char l[100]);
bool invalidletter(char letter, char in);
void main()
{
if (askquestion()){ starttest();}
}
void starttest()
{
char sentence[10][100];
int input;
int hi = 0;
int lengthofsentence;
int number= 0;
float time = 0.0;
int time2 = 0;
float wpm = 0.0;
DWORD StartTime;
system("cls");
strcpy(sentence[0], "Mary failed english class because she forgot to read her books.");
strcpy(sentence[1], "Jose fell down in gym class today and scraped his knees.");
strcpy(sentence[2], "Robert needs to get an A on his next test to pass history class.");
strcpy(sentence[3], "Jennifer went to Florida to visit her sister who is at college.");
strcpy(sentence[4], "In math class today I learned that ten times ten is one hundred.");
strcpy(sentence[5], "Don't you just love reading and typing these lame sentences.");
strcpy(sentence[6], "Do you try hard enough to be civilized in an uncivilized situation?");
strcpy(sentence[7], "After I wake up in the morning I brush my teeth and take a shower.");
strcpy(sentence[8], "If you pass the house with the green car in the driveway you went too far.");
strcpy(sentence[9], "Make sure you spend at least five hours in front of your computer.");
StartTime = GetTickCount();
for (int cnt = 0; cnt < 10; cnt++)
{
time = (GetTickCount() - StartTime) / 1000;
time2 = time;
wpm = (number / time) * 60;
printf("\n\nWords: %i\nTime: %i seconds\nWPM: %f\n\n", number, time2, wpm);
cout<<sentence[cnt]<<endl;
lengthofsentence = length(sentence[cnt]);
hi = 0;
while (hi < lengthofsentence)
{
input = _getch();
if (input == 8 || invalidletter(sentence[cnt][hi], input)) hi--;
++hi;
if (sentence[cnt][hi] == input){printf("%c", input); ++hi;}
if (sentence[cnt][hi] == ' '){number++;}
}
number++;
system("cls");
}
time = (GetTickCount() - StartTime) / 1000;
time2 = time;
wpm = (number / time) * 60;
printf("\n\nWords: %i\nTime: %i seconds\nWPM: %f\n\n", number, time2, wpm);
}
bool askquestion()
{
char answer;
cout<<"Would you like to see how many words per minute (WPM) you can type?";
cin>>answer;
if (answer == 'y' || answer == 'Y'){ return true; }
if (answer == 'n' || answer == 'N'){ return false; }
return false;
}
int length(char l[100])
{
int num = 0;
while (l[num] != '\0')
{
num++;
}
return num;
}
bool invalidletter(char letter, char in)
{
if (letter == in){ return true;}
return true;
}
PROPS to the first person who can answer why I named the program MBclone. Also don't bash my coding style instead I'm open for ideas on how to make my code more efficient and organized. enjoy.