#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
#include <iomanip.h>
#define FALSE 0
#define TRUE 1
float table_req(void); //Gets Multiplication Number
int lines_req(const float); //Gets number of lines
void print_out(const int, const float); //Print out of Table
int quit(void); //Check Continue request y/n
float input_number(void);
void main()
{
int exit = FALSE; //Exits program when TRUE
float table; //Multiplication Table
int lines; //Number of lines in table
do
{
table = table_req(); //Multiplication table
lines = lines_req(table); //Number of Lines in Table
print_out(lines,table); //Table Print out Function
exit=quit(); //Continue or quit entry
} while (exit==FALSE); //Continue while exit FALSE
clrscr(); //Clear Screen Function
cout << "\n\n\n\t Program Finished. \n\n";
}
float table_req(void)
{
float table;
do
{
clrscr();
cout << "\t\t\t MULTIPLICATION TABLES\n\n\n\n";
cout << "\n\n\t You can print any table between 1 and 20";
cout << "\n \t Which times table do you require? ";
cout << "\n\n \t Enter a floating point number.. ";
table = input_number();
} while (table <= 0 || table > 20);
return table;
}
float input_number(void)
{
const int LENGTH=10;
int decimal_point;
int i;
float number
char input_digit[LENGTH];
char key_touched;
int valid;
do
{
decimal_point = 0;
valid = TRUE;
gotoxy(58,10);
cout << " ";
gotoxy(58,10);
cin.getline(input_digit,LENGTH);
input_digit[LENGTH-1] = '\0';
for(i=0; (i<LENGTH && input_digit[i] != '\0'); i++)
{
switch(input_digit[i])
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
case '.':decimal_point++;
if (decimal_point > 1)
{
cout << '\a';
valid=FALSE;
}
break;
default: valid = FALSE;
cout <<'\a';
}
}
} while (valid == FALSE);
number = atof(input_digit);
return number;
}
int lines_req(const float table)
{
const int LINESLEN = 4;
int no_lines=1;
char input_lines[LINESLEN];
clrscr();
do
{
cout << "\n\n\n \t Lines required in " << table;
cout << " times table, integers 1 to 14 only. ";
if (no_lines < 1 || no_lines > 14)
{
cout << "\n\n \t Enter a VALID integer ";
cout << "between 1 and 14... ";
}
else
{
cout << "\n\n \t Enter an integer number ";
cout << "between 1 and 14...";
}
cin.getline(input_lines,LINESLEN);
input_lines[LINESLEN-1] = '\0';
no_lines = atoi(input_lines);
} while (no_lines < 1 || no_lines > 14);
return no_lines;
}
void print_out(const int lines, const float table)
{
int n;
clrscr();
cout << "\t " << lines << " LINES OF THE " << table;
cout << " TIMES MULTIPLICATION TABLE \n\n\n\n";
for (n=1; n <= lines; n++)
{
cout << "\t\t " << n << "\t Times \t " << table << "\t = \t ";
cout << setw(10) << n*table << '\n';
}
}
int quit(void)
{
char key_pressed;
int exit = FALSE;
do
{
cout << "\n\n\n\n\n\t Do you wish to quit ? Y or N ";
key_pressed=getch();
if (key_pressed != 'Y' && key_pressed != 'y'
&& key_pressed != 'N' && key_pressed != 'n')
{
cout << "\a\b";
clrscr();
}
} while (key_pressed != 'Y' && key_pressed != 'y'
&& key_pressed != 'N' && key_pressed != 'n');
if (key_pressed == "Y" || key_pressed == 'y')
exit = TRUE;
return exit;
}
I get the following 4 errors,
char input_digit[LENGTH];
This is a declaration Syntax Error.
cin.getline(input_digit,LENGTH);
This one is 'Undefined Symbol 'input_digit''
cin.getline(input_digit,LENGTH);
This one is 'Could not find a match for 'istream::getline(undefined,const int)'
if (key_pressed == "Y" || key_pressed == 'y')
and the last error is 'Cannot Convert 'Char' to 'Char *'.
I'm pretty bad at programming and I can't really understand whats wrong with the code here, I suspect its something obvious though.
Thanks in advanced,
and Hello all on DaniWeb.