In: Computer Science
I am having a difficult time with this loop. Needs to be in C++.
Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Ex: numRows = 2 and numColumns = 3 prints:
1A 1B 1C 2A 2B 2C
#include <iostream>
using namespace std;
int main() {
int numRows;
int numColumns;
int currentRow;
int currentColumn;
char currentColumnLetter;
cin >> numRows;
cin >> numColumns;
/* Your solution goes here */
cout << endl;
return 0;
}
Please find below code as per your requirement.
Thank you.
#include <iostream>
using namespace std;
int main()
{
int numRows;
int numColumns;
int currentRow;
int currentColumn;
char currentColumnLetter;
cout <<" Enter Row number :";
cin >> numRows;
cout << " Enter Column number :";
cin >> numColumns;
for (int i = 0;i<numRows;i++)//Number of rows
loop
{
currentColumnLetter = 'A';
for (int j = 0;
j<numColumns;j++)//Number of columns loop
{
cout << (i + 1) << currentColumnLetter << "
";//Print Seat number
currentColumnLetter++;//Gets next character
}
cout << " ";//For new row
}
return 0;
}
Output
Enter Row number :2 Enter Column number :3 LA 1B 10 2A 2B 2C C: Sample ProjectsCPlusPlusFirstConsoleApplicationDebugCPlusPlusFirstConsoleApplication.exe (process 19132) exited w th code e.