+ 1

Can anyone tell me why I can’t run this code properly??

#include <iostream> #include<iomanip> using namespace std; void main() { int height, width; cout << "Height:"; cin >> height; cout << "Width: "; cin >> width; char symbol; cout << "Symbol: "; cin >> symbol; for (int h = 0; h < height; h++); { for (int w = 0; w < width; w++) { cout << setw(3) << symbol; } cout << endl; } system("pause>0"); }

11th Nov 2022, 9:50 PM
Aymen
Aymen - avatar
7 Respuestas
+ 7
Trs Less the line formatting makes it almost unreadable and harder to find errors. Work on prettying up the code so it will be easier for you to spot syntax and logic errors. 1) #include directives must be on separate lines 2) The outer for loop statement has a spurious semicolon after the closing parenthesis that ends the statement prematurely. 3) The Sololearn run environment does not recognize the pause command. Comment it out if you want it to run here.
12th Nov 2022, 1:23 AM
Brian
Brian - avatar
+ 4
I've changed #include to seperate line & void method to int. This runs on sololearn. I'm not sure is that output you expect https://code.sololearn.com/cmdR4ddYV7NN/?ref=app
12th Nov 2022, 1:38 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 4
instead of using system("pause > 0"); you can use cin.get();
12th Nov 2022, 4:26 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 3
Azhagesanヾ(✿) please remove the semicolon (;) from line 15 It will run now. For better view, please insert cout<<endl; Between line 13 and 14.🙂 And may be you should comment or remove this line system("pause>0")
12th Nov 2022, 2:32 AM
Monika Bairagi
Monika Bairagi - avatar
+ 2
Thanks Monika Bairagi mistakes updated. Now it looks fine 👍
12th Nov 2022, 3:16 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
0
Does for loop end with semicolon? #error
12th Nov 2022, 4:16 AM
Omprakash
Omprakash - avatar
0
Hey gus im new here
13th Nov 2022, 9:48 PM
Steven Kisimba
Steven Kisimba - avatar