+ 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"); }
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.
+ 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
+ 4
instead of using system("pause > 0");
you can use
cin.get();
+ 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")
+ 2
Thanks Monika Bairagi mistakes updated. Now it looks fine 👍
0
Does for loop end with semicolon?
#error
0
Hey gus im new here