/*
Multiplication Table Generator v1.0
(C) Sudipto Ghosh. 2018.
*/
#include <iostream>
using namespace std;
// forward declarations for functions
void init(); int getValue(); void print();
int calc(int x, int y); int inputa, inputb;
char inputc; void prompt(); void program();
int main()
{
// 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;
// call the program into action
program();
// loop to start over our program
while (inputc != 'q')
{
program();
};
return 0;
}
void init()
{
// 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;
}
void program()
{
// initialise the generator
init();
// print the multiplication table
print();
// prompt if user wants to
// quit or start over
prompt();
}
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.
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.