You are here:



tis is my code tat i wrote for constucting the timetable.i do nt knw y it will go infinite loop.could you pls help me with my problem?

#include <iostream>
using namespace std;

// Function prototypes
int getInt (int);
void displayTimeTable (int,int);

int main ()
  int rows;
  int column;
  int n;
  int i;

  // Reading data validation
  rows = getInt (0);
  column = getInt (0);
   displayTimeTable (n,i);

int getInt (int i)
  int n;


     cout << "Enter the rows: ";
     cin >> n;
     cout << "Enter the column: ";
     cin >> n;
     cout << endl;
     if (n > 10)
        cout << "Please input a positive integer N that is smaller than 10"<<endl;
         cout << "Multiplication TimeTable"<<endl;
         cout << endl;
  }while (n < i);

  return n;

void displayTimeTable (int n,int i)
  cout << "*";
  for (int n = 1; n <= i; n++)
     cout << "\t" << n;
     cout << endl;
     cout <<"----------------------------------------------------------\n";
     for (int n = 1; n < i; ++n)
        cout << n;
        for (int j = 1; n < i; j++)
         cout << "\t" << n * j;
         cout << endl;

i will be delightful if you could help me.

Hi Crystal,

This call:

displayTimeTable (n,i);

with n and i have n and i undefined.  With:

displayTimeTable (rows,column);

works much better.  But there is a problem in getInt.  It reads 2 numbers but returns one.  You can get and return both rows and columns using reference parameters to getInt.  Or fix getInt to get rows or columns (one entry) and call it twice before printing the times table.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.