+ 2

Curly brackets

Hi boys and girls , In c++ , can we insert 2 {} blocks on the the same code ? If yes , how ; cause i've tried many times but it ouput a syntax error. ( my apologizes for my english)

21st Feb 2018, 9:08 PM
Pos1_TrOn
Pos1_TrOn - avatar
7 odpowiedzi
+ 1
I don't understand your problem. Send here your code please.
21st Feb 2018, 9:23 PM
Jan Štěch
Jan Štěch - avatar
+ 1
#include <iostream> using namespace std; int main() { int x= 76 + 40; cout << x <<endl; x= 98 + 456; cout << x <<endl; x= 765 - 876; cout << x <<endl; x= 7654 * 6; cout << x <<endl; x= 9876 / 0.25;//never divise by 0 cout << x <<endl; x= 80 % 7;//% remainder operator? cout << x <<endl; x= (9 + 2) * 2; cout << x <<endl; x= 987 + 78 * 2;//multiplication/division before addition/soustraction! cout << x <<endl; return 0; } { x= 76 + 76; cout << x <<endl; }
21st Feb 2018, 9:52 PM
Pos1_TrOn
Pos1_TrOn - avatar
+ 1
i've tried with a simple code but it was solded by an error
21st Feb 2018, 9:53 PM
Pos1_TrOn
Pos1_TrOn - avatar
+ 1
The second part of your code isn't in any function. You have to have everything in the main function, or you can create more functions outside the main, but you have to declare them proprlerly: E.G.: void sum(){ int x; x = (76 + 76); cout << (x); }
21st Feb 2018, 9:59 PM
Jan Štěch
Jan Štěch - avatar
+ 1
I recommend you to read functions tutorial in c++ course.
21st Feb 2018, 9:59 PM
Jan Štěch
Jan Štěch - avatar
+ 1
Understood ! Thanks Jan for the help :)
21st Feb 2018, 10:13 PM
Pos1_TrOn
Pos1_TrOn - avatar
0
You are welcome :-)
22nd Feb 2018, 5:42 AM
Jan Štěch
Jan Štěch - avatar