Question: I have the code created from the following problem : You are given a two-dimensional array of values that give the height of a terrain

I have the code created from the following problem :

You are given a two-dimensional array of values that give the height of a terrain at different points in a square. Write a function void flood_map(double heights[10][10], double water_level) that prints out a flood map, showing which of the points in the terrain would be flooded if the water level was the given value. In the flood map, print a * for each flooded point and a space for each point that is not flooded. Here is a sample map:

* * * * * *

* * * * * * *

* * * * * * *

* * * * * *

* * * * * * *

* * * * * * *

* * * * * * *

Then write a program that reads one hundred terrain height values and shows how the terrain gets flooded when the water level increases in ten steps from the lowest point in the terrain to the highest.

I am just trying to find a way to make the program print all the flood maps and pause at the end instead of having to press a key after every line of "*" in these 10 iterations. Even getting it to pause after a complet star map iteration and having to press a key to go on to the next map would be fine. I am using visual studio by the way.

CODE:

#include "stdafx.h"

#include

#include

#include

using namespace std;

void flood_map(double heights[10][10], double water_level);

void print(double heights[10][10]);

int main()

{

double heights[10][10];

double water_level;

srand(time(0));

int r = rand() % (200 - 10) + 100;

//read water level

for (int i = 0; i < 10; i++)

{

for (int j = 0; j < 10; j++)

{

//assign random value

heights[i][j] = rand() % 100;

}

}

//print heaights in 2-d Array

cout << "The 2-dimensional array of heights filled with random numbers within 100: " << endl;

print(heights);

//increase water leven in step of 10

int k = 1;

for (int i = 0; i < 100; i = i + 10)

{

cout << "For " << k++ << ": " << endl;

flood_map(heights, i);

}

}

void flood_map(double heights[10][10], double water_level)

{

for (int i = 0; i < 10; i++)

{

for (int j = 0; j < 10; j++)

{

if (heights[i][j]>water_level)

cout << "* ";

}

system("pause");

cout << endl;

}

}

void print(double heights[10][10])

{

for (int i = 0; i < 10; i++)

{

for (int j = 0; j < 10; j++)

{

cout << heights[i][j] << " ";

}

cout << endl;

}

cout << endl;

system("pause");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!