# can someone help me in c++?

I need help with my assignment

1.Write a C++ program that will calculate the result of (a+b)/2, use the right mathematical operator and correct datatypes.

2.Write a C++ program that will calculate the result of a+b*c/d, use the right mathematical operator and correct datatypes.

### 6 Answers

- Anonymous9 months agoFavourite answer
int A = value;

int B = value;

int result = A+B/2;

cout << result << end1;

system(“pause”);

- ∅Lv 79 months ago
did you NOT read the material? it's too easy for words to anyone who was actually paying attention.

go read it again or ask your teacher. that's why he's there.

if you cannot get it, perhaps coding is not for you. what are you gonna do when you are on your own out of school and have to figure things out yourself?

- Log in to reply to the answers

- Anonymous9 months ago
double niggera, niggerb;

cin >> niggera >> niggerb;

cout << ((niggera + niggerb) / 2.0);

- Log in to reply to the answers

- Anonymous9 months ago
ce we’re not together anymore, bur I don’t want it to be a thing you know? How do I do that?

- Log in to reply to the answers

- What do you think of the answers? You can sign in to give your opinion on the answer.
- husoskiLv 79 months ago
Since the average of two whole numbers can be a fraction, you should use a floating point type. For that, use double unless you have a specific reason to use float or long double.

Also, order of operations in C++ is approximately the same as in regular algebra's PEMDAS: Parentheses, Multiply and Divide, Add and Subtract. So, if you want to add two numbers and then divide by 2, you need parentheses around the division, as in (a + b)/2 rather that a+b/2.

Finally, C++ chooses the type of arithmetic to do based on the numbers used, not based ton the type of the result. For example 7/2 uses int values 7 and 2, so C++ does int division producing an integer result 3 (and discarding the remainder). If you want to compute in floating point, at least one of the the numbers must be floating point.

Put all that together and you get:

double result = (A + B) / 2.0;

- Log in to reply to the answers

- VPLv 79 months ago
You need to show us your program and tell us what part(s) confuses you. If you run your program and it gets errors, tell us what the errors are.

- Log in to reply to the answers

Anonymous === Anonymous