Solved

for loop

Posted on 1998-09-19
1
247 Views
Last Modified: 2010-04-01
I have a function that accepts three ints
void outdata(int num1,int num2, int pline)
{
  for (int i=num1;i<num2;i++)//this is for printing the
    cout<<i;                //  range of numbers.
I need a for loop to print the pline which is the number
to printed out per line.
I am sure that there is a simply fix I am over looking the
easy solution again
any help would be great.
Thank you  
 

 
0
Comment
Question by:strmtrpr
1 Comment
 

Accepted Solution

by:
dave81 earned 50 total points
ID: 1173178
Like this?

void outdata( int num1, int num2, int pline )
{
  int curCount = 0;
  for( int i = num1; i < num2; i++ )
  {
    cout << i;
    curCount++;
    if( curCount == pline )
    {
      cout << endl;  // new line
      curCount = 0;  // reset the count
    }
  }
}
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question