Deleting Rows

How can i delete a row in a nested loop?
if i have 5 rows, how can i delete the 3rd row?(or other rows?)

********
********

********
********
Make each row a class char array.

Delete that row by just turning "******" into "";
1
2
3
4
if (innerLoopIndex == 3)
{
    3rdRowVar = NULL;
}
Last edited on
i'm trying to use a for statement

for (int line = 1; line <= row + 1; line += 1)
{
for (int numAst = 1; numAst < column + 1; numAst += 1)
cout << '*' << " ";
cout << endl;

how can i delete a certain row?
I think he wants to delete it by will
1
2
3
4
5
6
7
8
9
10
11
12
13
int delRowVar;
cout << "Which row you want gone?";
cin >> delRowVar;
for (int line = 1; line <= row + 1; line += 1)
{
for (int numAst = 1; numAst < column + 1; numAst += 1)
    if ( numAst == delRowVar )
    {
        continue;
    }else{
    cout << '*' << " ";
    cout << endl;
    }
Last edited on
my out put should be like this...

Enter number of row:
enter number of column:
enter row to be deleted:

e.g.

Enter number of row: 4
enter number of column: 5
enter row to be deleted: 2

*****

*****
*****


how can i do it?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

int main()
{
int delRowVar;
int row, column;
cout << "Enter rows: ";
cin >> row;
cout << "Enter columns: ";
cin >> column;
cout << "Which row you want gone?";
cin >> delRowVar;
for (int line = 1; line <= row + 1; line++)
{
	if ( line == delRowVar )
    {
       cout << "deleted" << endl;
	   line++;
	   continue;
	}else{
		for (int numAst = 1; numAst < column + 1; numAst++){
		cout << '*' << " ";
		}
		cout << "\n";
	}
}
}


Line 21 is just for debugging and you can remove it
Last edited on
thank you rcast :)
I'm learning too, thank you.
I made a couple changes to the loop to make the loop conditions consistent (i.e. both use <= and neither need a +1) and remove the unnecessary line++; and continue;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
    for (int line = 1; line <= rows; line++)
    {
        if ( line == delRowVar )
        {
           cout << "deleted" << endl;
        }
        else
        {
            for (int numAst = 1; numAst <= columns; numAst++)
            {
                cout << '*' << " ";
            }
            cout << "\n";
        }
    }
Last edited on
<----- He's right. Unnecessary line++ and continue. As I said before, we're both learning :)
Here you go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(int nNumberofArgs,char* pszArgs[])
{
	char grid[5][5] = {{'\xB2','\xB2','\xB2','\xB2','\xB2'},
                        {'\xB2','\xB2','\xB2','\xB2','\xB2'},
                        {'\xB2','\xB2','\xB2','\xB2','\xB2'},
                        {'\xB2','\xB2','\xB2','\xB2','\xB2'},
                        {'\xB2','\xB2','\xB2','\xB2','\xB2'}};
	int x,y,I;

	for(;;)
    {
        I = 0;
        for(int i = 0;i < 5;i++)
        {
            for(int j = 0;j < 5;j++)
            {
                cout << grid[i][j];
            }
            cout << endl;
        }
        cout << endl << endl;
        cout << "Choose a spot to delete: " << endl;
        cout << "X: ";
        cin >> x;
        cout << "Y: ";
        cin >> y;

        grid[y-1][x-1] = ' ';
        for(int i = 0;i < 5;i++)
        {
            for(int j = 0;j < 5;j++)
            {
                if(grid[i][j] == '\xB2')
                {
                    I++;
                }
            }
        }

        if(I == 0)
        {
            cout << "You destroyed the cake!" << endl;
            break;
        }
    }

	return 0;
}
Topic archived. No new replies allowed.