OK, any help would be very much appreciated. I’m trying to make a program where I’m creating a grid pattern (Easting, Northing and Elevation) and then exporting it into a .txt sheet. Were I'm getting caught up is how to format the FOR loop. Can you do more than a nested FOR loop (ie 4 or 5 times)?Here are the questions I ask:
• What is your starting Easting point.
• What is the Easting spacing (This is how far the new point would be east)
• What is your starting Northing point.
• What is the Northing spacing(This is how far the new point would be North)
• How many columns will there be (this is how many times the Easting will repeat itself. Essentially columns)
• How many rows will there be(this is how many times the northing will repeat itself. Essentially rows)
• What elevation will it be starting? (essentially how deep the Z will start to output)
• What elevation will it be terminating? (essentially when the Z will stop outputting)
• What is the elevation spacing? (How many times I want the Z to output)
I’ll give you an example of what I’m looking for:
• What is your starting Easting point. = 100
• What is the Easting spacing (This is how far the new point would be east) = 5
• What is your starting Northing point. = 200
• What is the Northing spacing(This is how far the new point would be North) 10
• How many columns will there be (this is how many times the Easting will repeat itself. Essentially columns) = 5
• How many rows will there be(this is how many times the northing will repeat itself. Essentially rows) = 10
• What elevation will it be starting? 10
• What elevation will it be terminating? 50
• What is the elevation spacing? 5
EAST NORTH Elevation
100 200 10
100 200 15
100 200 etc to 50
105 200 10
105 200 15
105 200 etc to 50
This will go on to when Easting reaches 150 because I wanted 5 foot spacing and wanted it to happen 10 times.
Then we start on the next row where the north has changed to 210 and it will end at 300 because I wanted 10 spacing
EAST NORTH Elevation
100 210 10
100 210 15
100 210 etc to 50
100 220 10
100 220 15
100 220 etc to 50
Here is my current code:
#include <iostream>
#include <fstream>
#include <ostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
void mainInfo(double & easting, double & northing, double & elevation, int & rows, int & columns, int & eastSpace, int & northSpace, int & elevSpace);
void getInfoSame(double & easting, double & northing, double & elevation, int & rows, int & columns, int & eastSpace, int & northSpace, int & elevSpace);
void getInfoDiff();
int main()
{
double easting;
double northing;
double elevation;
int rows;
int columns;
int eastSpace;
int northSpace;
int elevSpace;
char rowAnswer;
Yes, it's perfectly fine to nest for-loops.
Do keep in mind that as you nest them. complexity grows quite fast, ie:
1 2 3 4 5 6 7 8 9 10 11
for (int i=0; i<10; i++)
//this line is executed 10 times
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
//this line is executed 100 times
for (int i=0; i<10; i++)
for (int j=0; j<10; j++)
for (int r=0; r<10; r++)
//this line is executed 1000 times
This may have an impact if you're executing heavy duty code within the loops.
On a sidenote, please wrap your code in [code][/code] tags in the future - it makes it more readable for us.
Please do let us know if you have any further questions.