Thread: What I am doing wrong here?

  1. #1
    Banned
    Join Date
    Apr 2011
    Posts
    56

    What I am doing wrong here?

    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

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What's wrong with your code here? Your code is C++, this is the C forum.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Banned
    Join Date
    Apr 2011
    Posts
    56
    sorry, my bad, I had been working on C but this project was on C++. Didn't realize that I submitted it in C section.

    Can I move it?
    Last edited by Iron Hide; 05-11-2011 at 05:01 PM.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Already got the code handed to him here. Good thing you didn't have to think too much, huh?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wrong wrong with my xor function?
    By Anddos in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2009, 01:38 PM
  2. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-28-2005, 12:48 AM
  3. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  4. What's wrong with this?
    By dat in forum C Programming
    Replies: 7
    Last Post: 06-20-2003, 11:22 PM
  5. what's wrong here?
    By phptech in forum C Programming
    Replies: 1
    Last Post: 06-19-2003, 07:51 PM