Multiplication Table Generator v1.0

/* Multiplication Table Generator v1.0 (C) Sudipto Ghosh. 2018. */ #include <iostream> using namespace std; // forward decarations for functions void init(); int getValue(); void print(); int calc(int x, int y); int inputa, inputb; char inputc; void prompt(); int main() { // initialise the generator init(); // print the multiplication table print(); // prompt if user wants to // quit or start over prompt(); // loop to start over while (inputc != 'q') { init(); print(); prompt(); }; return 0; } void init() { // welcome message for the user cout << "Welcome to the mutipication table generator !" << endl; cout << "Output wil be printed in the following format:" << endl; cout << "a\t*\tb\t=\ta*b" << endl; // get the number whose table is required cout << "Value of a is? "; inputa = getValue(); // get the range of the table to be generated cout << "Enter the number of rows required: "; inputb = getValue(); cout << endl; } int getValue() { int a; cin >> a; return a; } void print() { // loop the printing job for(int loopCount(1); loopCount <= inputb; loopCount++) { cout << inputa << "\t*\t" << loopCount << "\t=\t" << calc(inputa,loopCount) << endl; }; } int calc(int x, int y) { return x * y; }; void prompt() { // prompt if further action is required else quit cout << endl << "Press q to quit\t\tPress any other key to start over."<< endl; cout << "Your reply: "; cin >> inputc; }
Just a multiplication table generator that greets the user with a welcome message and gives a sample output. It then asks the user for the number whose multiplication table is required and range of the table. It prompts the user after printing output whether the user wants to quit or start over.

I thought if forward declarations and a modular main() function were used, it looked more nicer.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.