+ 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)
7 Answers
+ 1
I don't understand your problem. Send here your code please.
+ 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;
}
+ 1
i've tried with a simple code but it was solded by an error
+ 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);
}
+ 1
I recommend you to read functions tutorial in c++ course.
+ 1
Understood ! Thanks Jan for the help :)
0
You are welcome :-)