Solved

for loop

Posted on 1998-09-19
1
233 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 142
C++ assignment question 7 169
Excel/Word Add-in in what language? 5 107
C++ finding a sting in a char* string from a text file 3 99
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now