Here is my code:
Code:
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
int getNumber();
int printnumPerLine();
void printResult(int, int);
int main()
{
int num;
int numPerLine;
num = getNumber();
numPerLine = printnumPerLine();
printResult(num, numPerLine);
}
//get input from keyboard and return it to caller
int getNumber()
{
int num;
cout << "\n\nPlease enter a non-negative number: ";
cin >> num;
return num;
}
int printnumPerLine()
{
int numPerLine;
cout << "\nHow many numbers per line? ";
cin >> numPerLine;
return numPerLine;
}
//print our result
void printResult(int num, int numPerLine)
{
int i = 0;
do{
cout << setw(4) << i;
i++;
} while (i<=num);
if(i % numPerLine == 0){
cout << endl;
}
cout << endl << endl;
}
It is suppose to print user defined number of lines, but for some reason its not working. I had been using for loop and I can make it work in for loop, but I need to learn do while too. Please let me know what am I doing wrong here. The problem is at the if statement I guess.
Thanks