ASSIGNMENT | Sololearn: Learn to code for FREE!

-4

ASSIGNMENT

A,b,c are variables of type int while d, e f and g are of type float. If a= 4, b = 6 and c -3, Find • d=3a + -ac • f = d/a • e = f+2c • g = f/e

c++

2/17/2021 3:58:00 PM

OGYIRI MICHAEL

6 Answers

New Answer

+3

Please add-show your attempt so the community can help you more easily :)

0

SOLUTION #include <iostream> using namespace std; int main () { int a = 4, b = 6, c= -3, d; d=3a+ -ac; d=float(3*a) + float(-a*c); d=(3*4 )+(-4*(-3); d=12+ 12; //24 d=24; cout<<“d is “<< d<<endl; return 0; } #include <iostream> using namespace std; int main () { int a = 4, b = 6, c= -3, d=24; f = d/a; f=24/4; //6 f=6; cout<<"f is "<<f<<endl <<"d is "<<d; return 0; }

0

Tips: - There should be only one "int main ()" function. - Unary "-" function has a lower precedence than binary "*" operator, so "-x * y" should be "(-x) * y)", otherwise it will be evaluated as "-(x * y)". - "x + -y" and "x - -y" should be "x + (-y)" and "x - (-y)", otherwise it will be an error. - Writing no operator between operands in C++ and other languages does not doing multiplication on those operators. You should always write multiplication sign (in case of programming it is "*") when and where you want operands to be multiplicated. - You should declare a variable with its type before its name before the variable to be used. - You should just write the original expression: for example, for d the code is "float d = 3 * (float) a + ((-a) * c);". - You can (sure, if it is not forbidden in the assignment) use intermediate variables: "float a_f = a, b_f = b, c_f = c;" and use them in expressions instead, thus, there will be no need to write "(float)".

0

#include <iostream> using namespace std; int main () { int a = 4, b = 6, c= -3, d; d=3a+ -ac; float d = 3 * (float) a + ((-a) * c); d=3*(4+(-4*(-3); d=3*(4+12); d=3*16;//48

0

I`m actually a beginner what next after the float d = 3 * (float) a + ((-a) * c);". #include <iostream> using namespace std; int main () { int a = 4, b = 6, c= -3, d; float d = 3 * (float) a + ((-a) * c);".

0

OGYIRI MICHAEL, 1) Do this for all the remaining variables. 2) Take the C++ course on SoloLearn (free) to understand the basics. To do your task, https://www.sololearn.com/learning/1603/ , https://www.sololearn.com/learning/4120/ , https://www.sololearn.com/learning/1606/ , https://www.sololearn.com/learning/1607/ , https://www.sololearn.com/learning/1608/ , https://www.sololearn.com/learning/1609/ , https://www.sololearn.com/learning/1610/ , https://www.sololearn.com/learning/1621/ , https://www.sololearn.com/learning/1622/ is enough. 3) You must to not put double quotation mark at the end of the expression, because it will be treated as string start without end => error.