You are viewing our Forum Archives. To view or take place in current topics click here.
can somebody please help me with c++ here is my source code
Posted:
can somebody please help me with c++ here is my source codePosted:
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
im having trouble understanding c++
this is my source code
a + b * c + d = 55 but it is ment to equal 100. what is wrong with my coding?
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 5;
int c = 5;
int d = 5;
cout << a + b * (c + d);
cin.get();
return 0;
}
this is my source code
a + b * c + d = 55 but it is ment to equal 100. what is wrong with my coding?
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 5;
int c = 5;
int d = 5;
cout << a + b * (c + d);
cin.get();
return 0;
}
#2. Posted:
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201114Year Member
Posts: 1,957
Reputation Power: 401
UK_cHaDd3rZ wrote im having trouble understanding c++
this is my source code
a + b * c + d = 55 but it is ment to equal 100. what is wrong with my coding?
#include <iostream>
using namespace std;
int main()
{
int a = 5;
int b = 5;
// a+b = 10
// c+d = 10
// a+b * c+d = 100
int c = 5;
int d = 5;
cout << a + b * (c + d);
cin.get();
return 0;
}
This is BODMAS (Bracket, Over, Divide, Multiply, Add, Subtract)
If you enclose a + b AND c + d in brackets, the Maths Processor will work those out first, then multiple the 2 together.
at the moment it does
(c + d) = 10
b * 10 = 50
a + 50 = 55
you want it to
(a + b) = 10
(c + d) = 10
10 * 10 = 100
so
cout << (a + b) * (c + d);
That should sort you out.
- 1useful
- 0not useful
#3. Posted:
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
Status: Offline
Joined: Sep 05, 201212Year Member
Posts: 384
Reputation Power: 14
ahh right thankyou for the help it works okay now and i understand it
- 0useful
- 0not useful
#4. Posted:
Status: Offline
Joined: Jan 04, 201113Year Member
Posts: 1,732
Reputation Power: 72
Status: Offline
Joined: Jan 04, 201113Year Member
Posts: 1,732
Reputation Power: 72
Yea PEMDAS remember that....
- 0useful
- 0not useful
#5. Posted:
Status: Offline
Joined: Dec 23, 201014Year Member
Posts: 2,446
Reputation Power: 80
Imp wrote This is BODMAS (Bracket, Over, Divide, Multiply, Add, Subtract)
I have honestly never heard of BODMAS, but it seems to work fine.
- 0useful
- 0not useful
#6. Posted:
Status: Offline
Joined: Sep 19, 201014Year Member
Posts: 8,159
Reputation Power: 394
Status: Offline
Joined: Sep 19, 201014Year Member
Posts: 8,159
Reputation Power: 394
Even wroteImp wrote This is BODMAS (Bracket, Over, Divide, Multiply, Add, Subtract)
I have honestly never heard of BODMAS, but it seems to work fine.
BEDMAS, PIMDAS, BODMAS, PEDMAS...
There are a bunch of different names but they're all the same thing.
- 1useful
- 0not useful
You are viewing our Forum Archives. To view or take place in current topics click here.