Assume that qty and salesRep are both integers. Use a type cast expression to rewrite the following statements so it will no longer perform integer division
unitsEach = qty / salesRep
This is what I wrote
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
int qty,salesReps;
cout<<"Enter the value of qty : "<<endl;
cin>>qty;
cout<<"Enter the value of salesReps : "<<endl;
cin>>salesReps;
float unitsEach = qty / salesReps;
cout<<"The value of unitsEach is : "<<unitsEach<<endl;
return 0 ;
}
#include <iostream>
usingnamespace std;
int main()
{
int qty,salesReps;
double unitsEach;
cout<<"Enter the value of qty : "<<endl;
cin>>qty;
cout<<"Enter the value of salesReps : "<<endl;
cin>>salesReps;
unitsEach = static_cast<double>(qty) / salesReps;
cout<<"The value of unitsEach is : "<<unitsEach<<endl;
return 0 ;
}
Please create separate topics for unrelated problems. As for your question, the problem is here:
number1 + number2 = sum;
Let's break down what happens:
- number2 is added to number1, creating a temporary result (also known as an rvalue)
- an rvalue cannot be assigned a new value, which is what you are trying to do by doing = sum
"sum" is an lvalue, basically meaning it can be of the left side of operator=(). All this to say that this line should look like this: