Alright, I have a loop with a few nested loops inside like so:

........

for (int s=0; s<200; s++)
{
      for (int i=0; i<N_plates; i++)
    {

               for (int j=0; j<3; j++)
        {
                     V=V+(Cen[i][j])*(N[i][j]);
                 }
                    for (int j=0; j<3; j++)
            {
                          ................
                         }
         }
  V=V/6;
  cout << "Volume:" << V << endl;
}

Alright, so the problem I am having with this is that I only want "V" to print once to the screen. However, its printing as many times as the primary loop tells it too.

The only way around this that I have in mind is to set this "V" as an array and tell it to print it once.

Is there any other way to get it to print once without having to write it as an array or changing the structure of the program.

Thanks

Please use the code tags, like

[code]

your code goes here

[/code]
This will make your code more readable, assuming you had proper indentation to begin with.
What you posted should look like:

for (int s=0; s<200; s++)
   {
      for (int i=0; i<N_plates; i++)
      {

         for (int j=0; j<3; j++)
         {
            V=V+(Cen[i][j])*(N[i][j]);
         }
         for (int j=0; j<3; j++)
         {
            ................
         }
      }
      V=V/6;
      cout << "Volume:" << V << endl;
   }

Now it's easier to see what's within what.

If all you want to see with V is the final value, put the output statement outside of the outer loop. But is that really what you want, as that will be a V that has been updated 200 * N_plates * 3 times.

Perhaps an explanation of what you're doing will help get better help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.