what's wrong with this code???

I wanna output the table but can't get the desired output!!!

//table generator.
#include<iostream>
#include<conio.h>
using namespace std;
int table() {
int a;
for( int i=1; i<=20; i++ ) {
cout <<"\t"<<a<<"*"<<i<<"="<<a*i<<endl; }
}
int main()
{
int n;
cout << " >>>This Program Takes a Number From User And Generates its 20 Multiples<<<\n\n";
cout << "Enter the number : ";
cin >> n;
cout << "Here's the table of " << n << endl;
n = table();
getch();
}
Last edited on
Hi Soldier,

Hey as I understood in above code you are trying to print table of number given by user up to 20.

If above is right then you should provide user given no in to your table() as argument.
like - int table(int n)

so table function become -

int table(int no) {
int a = no;
for( int i=1; i<=20; i++ ) {
cout <<"\t"<<a<<"*"<<i<<"="<<a*i<<endl; }
}

and call become -

int main()
{
...
....
.

table(n);


....

}

Hi Soldier,

is your problem solved or is there any problem?
thnks a lot!!! ak16
it worked :)
Topic archived. No new replies allowed.