This is my final project for my C++ class online. I was instructed to make a test and to pull answers from withing a .txt file and compare them to the answer that the user inputs. I'm sure there's a much easier wau of doing things than the way I'm doing them, but that desn't matter to e right now. What matters to me is why I can't link my program(it compiles fine). Observe this code here:
//"Derek Elensar"
//Final Project.cpp
#include <iostream>
#include <fstream>//.h>
#include <string.h>
#include <iomanip>//.h>
#include <string.h>
#include <stdio.h>
#include <cstdlib>
/*
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::ios;
using std::fstream;
using std::fixed;
*/
using namespace std;
double check_answer(char user_answer[2], char answer_from_file[2] , double);
char check_case(char user_answer[2]);
int main()
{
double percentage;
const int points_possible = 20;
fstream answers_in;
char user_answer[2];
char answer_from_file[2];
double tempscore;
fstream score_out;
char firstname[16], lastname[16];
cout << "What is your first name?\n>";
cin.get(firstname, 16);
cin.ignore(80, '\n');
cout << "What is your last name?\n>";
cin.get(lastname, 16);
cin.ignore(80, '\n');
strcat(firstname, " ");
strcat(firstname, lastname);
strcat(firstname, ".TXT");
answers_in.open("ANSWERS.TXT", ios::in);
score_out.open(firstname, ios::out);
if(!answers_in)
{
cout << "ERROR: Could not open answers.txt!\n";
return 0;
}
if(!score_out)
{
cout << "ERROR: Could not output score file!\n";
return 0;
}
else
{
system("CLS");
//1
cout << "choose A\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//2
cout << "choose B\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//3
cout << "choose C\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//4
cout << "choose D\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//5
cout << "choose A\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//6
cout << "choose B\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//7
cout << "choose C\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//8
cout << "choose D\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//9
cout << "choose A\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//10
cout << "choose B\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//11
cout << "choose C\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//12
cout << "choose D\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//13
cout << "choose A\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//14
cout << "choose B\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//15
cout << "choose C\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//16
cout << "choose D\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//17
cout << "choose A\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//18
cout << "choose B\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//19
cout << "choose C\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//20
cout << "choose D\n"
<< "A) answer\tB) answer\n"
<< "C) answer\tD) answer\n";
cin.get(user_answer, 2);
cin.ignore(80, '\n');
user_answer[0] == check_case(user_answer);
answers_in >> answer_from_file;
system("CLS");
tempscore = check_answer(user_answer, answer_from_file, tempscore);
//================================================
percentage = (tempscore / points_possible) * 100;
cout << "You got " << tempscore << '/' << points_possible
<< " meaning that\n Your score was a " << percentage << "%\n";
}
answers_in.close();
score_out << percentage << "%\n";
score_out.close();
return 0;
}
double check(char user_answer[2], char answer_from_file[2], double tempscore)
{
if(strcmp(user_answer, answer_from_file) == 0)
{
tempscore++;
//cout << tempscore << endl;
}
return tempscore;
}
char check_case(char user_answer[2])
{
if(user_answer[0] == 'a' || user_answer[0] == 'b' || user_answer[0] == 'c' || user_answer[0] == 'd'){
user_answer[0] -= 32;}
return user_answer[0];
}
now when I compile, I get these errors:
undefined reference to `check_answer(char*, char*, double)'|
undefined reference to `check_answer(char*, char*, double)'|
undefined reference to `check_answer(char*, char*, double)'|
undefined reference to `check_answer(char*, char*, double)'|
undefined reference to `check_answer(char*, char*, double)'|
more undefined references to `check_answer(char*, char*, double)' follow|
||=== Build finished: 6 errors, 0 warnings ===|
It doesn't give me any line numbers or anything, and I'm quite baffled at my sityation... If someone could help me with this, I would greatly appreciate it.
DISCLAIMER: this IS homework, and I'm not asking for you to do it for me.. as you can see, I have it pretty much all done(except for actually putting the questions in there meself.. I gotta think about what I wanna ask :P )I am merely asking for help with the errors that I'm getting.
Thanks,
Derek Elensar
:)