- 3
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
6 Answers
+ 4
Please add-show your attempt so the community can help you more easily :)
+ 1
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;
}
+ 1
#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
+ 1
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);".
+ 1
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 not put double quotation mark at the end of the expression, because it will be treated as string start without end => error.
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)".