Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 9 months ago

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.

Relevance
• Anonymous
9 months ago

int A = value;

int B = value;

int result = A+B/2;

cout << result << end1;

system(“pause”);

• Quentin
Lv 7
9 months agoReport

Anonymous === Anonymous

• Lv 7
9 months ago

did you NOT read the material? it's too easy for words to anyone who was actually paying attention.

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?

• Anonymous
9 months ago

double niggera, niggerb;

cin >> niggera >> niggerb;

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

• Anonymous
9 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?

• 9 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;