![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
Just like to know why
This code asks the user how many rows he would like and how many columns he would like plus what character he wants to print. Then it uses a nested for loop to print the output:
int main() { int rows, columns; char theChar; cout << "How many rows? "; cin >> rows; cout << "How many columns? "; cin >> columns; cout << "What character? "; cin >> theChar; for(int i = 0; i < rows; i++) { for(int j = 0; j < columns; j++) cout << theChar; cout << "\n"; } return 0; } Now the code works fine. But if I remove the opening brace and closing brace for the for loop, and say input 5 for rows and 5 for columns it will print like this: ************************* I'd like to understand why it does that. Is it because there are actually 2 statements in the body of the inner loop? And without the braces only the cout << theChar statement will run? Just like to be clear on this. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|