Last minute homework fix after a week of procrastination =P
An ISBN number, as you already know, has either 10 or 13 letters with 3 or no dashes stuck in between.
The short version the the story is that this program is to validate ISBN numbers either by user input or calling up a text file in your directory.
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
#define inFile "isbntest.txt"
////////// FUNCTIONS USED //////////
istream& FLUSH(istream& stream);
void menu(); // MENU
void manual(); // ISBN BY USER
void done(); // QUIT
int byfile(); // ISBN BY FILE
bool checkISBN(); // VALIDATING ISBN
#define ENDFILE "CTRL-Z"
int main()
{
ifstream fin;
ofstream fout;
char option;
string isbn;
fin.open("inFile");
fout.open("inFile");
do
{
menu();
cout << ": " << endl;
cin >> option;
switch(option)
{
case 1:
manual();
break;
case 2:
byfile();
break;
case 3:
done();
break;
default:
cerr << "Incorrect selection! Please try again: " << endl;
}
}
while (option != '3');
fin.close();
fout.close();
system("pause");
return 0;
} // END MAIN
////////// FUNCTION MENU //////////
void menu()
{
cout << "Hello!" << endl << endl;
cout << "This program verifies the ISBN(s) that you insert " << endl << endl;
cout << "\t To manually insert an ISBN, enter '1' " << endl;
cout << "\t To call up ISBN from an internal file ISBN.txt, enter '2' " << endl;
cout << "\t If you are finished and would like to exit, enter '3' " << endl << endl;
cout << "Have fun =D " << endl;
}
////////// FUNCTION MANUAL //////////
void manual()
{
string isbn;
do
{
cout << "Enter an isbn or press "
<< ENDFILE << ": ";
cin.get(isbn); // EXTRACTING ISBN
checkISBN();
if (checkISBN() == true)
fout << "This is a valid ISBN." << endl;
else
fout << "This is an invalid ISBN. " << endl;
fout << "If you would like to quit, enter 'q' " << endl;
fout << "If you would like to try again, enter an ISBN " << endl;
fin << isbn;
}
while(isbn != ENDFILE);
} // END MANUAL
////////// FUNCTION FILE //////////
int byfile()
{
string filename;
string isbn;
int count;
fout << "Enter the input file name: ";
fin >> filename; // USER INPUT FOR FILE DIRECTORY
fin.open(filename.c_str());
if (cin.fail())
{
fin >> count;
fin.ignore(80, '\n');
while(!fin.eof())
{
getline(fin, isbn);
if(isbn.(isbn.length() -1) == '\o')
{
isbn.erase(isbn.length()-1,1)
}
}
cerr << " ***ERROR: Cannot open " << filename
<< " for input. " << endl;
return EXIT_FAILURE;
}
else
checkISBN(isbn);
fin.close();
}
/////////// FUNCTION DONE ///////////
void done()
{
cout << "Thank you for using this program. " << endl << endl;
cout << "Have a nice day :) " << endl;
}
////////// FUNCTION CHECKISBN //////////
bool checkISBN(isbn)
{
int charCount;
int dashCount;
int length;
int i;
string isbn;
for (int i = 0; i < 80; i++) // DEFINING 'i'
(!isdigit(isbn.at(i));
length = isbn.length();
if(length != 10 && length !=13) // DEFINING LENGTH
{
cerr << "Wrong length! Please try again! " << endl;
FLUSH(fin);
return(false);
}
else
isbn.at();
dashCount = 0;
{
if(isbn.at(i) == '-') // DEFINING DASHCOUNT
{
++dashCount;
}
}
if(dashCount != 0 && dashCount !=3)
{
cerr << "Invalid number of dashes! Please try again! " << endl;
return(false);
}
else
cout << "***Valid ISBN*** " << endl;
}
////////// FUNCTION FLUSH //////////
istream& FLUSH(istream& stream)
{
stream.clear();
int ch;
while ((ch = stream.get()) != '\n' && ch != EOF)
{
; // Do nothing inside loop - it's all in the condition!
}
stream.clear();
return stream;
}
And obviously... it does not run
I'm sorta new on the whole programing scene and I know I can't do all this without some kind of help...
On debugging specifically and why it does not run
Some of the errors I'm getting are
-isbn is an undeclared identifier
-fout is an undeclared identifier
-and various semicolon errors....
umm help?
<edit>: gee I'm dumb, I declared it as an int and wrote it as void ><;;
but I've still got a lot of debugging left....
This post has been edited by spylace: 05 November 2008 - 01:50 AM

New Topic/Question
Reply




MultiQuote




|