Why your original code doesn’t give 7.375 and how to get it
Problem: all your variables are int, so every division uses integer division (it truncates the fractional part). That makes d = c / b evaluate to 4 (not 4.5), and then
e=3+4+18+44=294=7
so cout << e prints 7.
To get 7.375 you must perform floating‑point division for the step that produces 4.5 and for the final average. Convert the divisor or numerator (or the result variable) to a floating type (double or float) so C++ does real division.
Minimal corrected code (simple, clear fix)
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int a = 3;
int b = 4;
int c = (a % b) * 6; // (3 % 4) = 3 -> c = 18
double d = static_cast<double>(c) / b; // 18 / 4.0 = 4.5
double e = (a + b + c + d) / 4.0; // (3 + 4 + 18 + 4.5) / 4 = 7.375
cout << fixed << setprecision(3) << e << endl; // prints 7.375
return 0;
}
Key points
Integer division truncates: 18 / 4 → 4.
Floating division required: 18 / 4.0 → 4.5.
Use double (or float) for d and e, or cast operands with static_cast<double>(...).
Use 4.0 (not 4) when dividing to force floating‑point arithmetic.
That change yields the desired result 7.375