Folks, I've been tasked with writing a program that calls functions from a tutor provided class. It stores a essentially the functions to create a spelling test program. I ask it for the next question, get some user input to ask if a word is spelt correctly, send the users answer (which is supposed to be a char 'y' or 'n') and am returned a true or false as to whether the user was wrong.
At this point in time however I cannot stop sending the \0 charachter because when the user inputs a character, they press enter afterwards. The code is written also using a lib supplied by the tutor, that replaces stdio.h, because the idea is learning how to use classes... ReadChar(); simply reads the last charachter from the screen and returns it. If you guys need any further explanation I'll happily provide it.
Code:
#include <vcl.h>
#include "MT262io.h"
#include "SpellQuiz.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
QuizType MyQuiz; // Declare a QuizType object.
// Your code goes here.
//var's
char UsrAttempt;
int Score;
bool More; //make this a bool and then test it?
bool temp;
//Init
MyQuiz.Initialise();
Score = 0;
while(More)
{
//Display Prompt and get question
WriteString("Is the following spelt correctly?\n y\n: ");
WriteString(MyQuiz.GetNextQn());
//Get User Input
fflush(stdin);
UsrAttempt = ReadChar();
//Test Guess and print relevant info (this form of if will be run
//when condition is true)
temp = MyQuiz.Guess(UsrAttempt);
if (temp == true)
{
Score = Score + 1;
WriteString("Correct!");
WriteIntPr("Your Score is now ", Score);
}
//If user guesses wrong the score is not incrimented
if (temp == false)
{
WriteString("Wrong!");
WriteIntPr("Your Score is now ", Score);
}
else
{
WriteString("Error, neither true or false returned");
}
More = MyQuiz.AnyMore() == true;
}
getchar();
return 0;
}
I'm aware its quite cumbersome, and for some reason the compiler I'm using (Builder 5) won't allow me to debug most of the lines of the code hence the temp variable. I'm perplexed as to how I can get the users answer and not the \0 char though
Thanks!!!!