Take percentage of each input as it is being input 2

When I run my program, I get the result I am looking for, however, I get a warning from the compiler that says: warning C4244: '=' : conversion from 'double' to 'float', possible loss of data

I would appreciate feedback on how I can write more efficient code that will calculate the percentage for each variable as it is input by the user and then total up these 4 values.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <iostream>
using namespace std;
int main()
{
	float test1_score, test2_score, final_score, assign_score, total_score;

	cout << "Enter your Test 1 score, Test 2 score, Final score, and Assignments score." << endl;

	cin >> test1_score;//read in Test 1 score
	cin >> test2_score;//read in Test 2 score
	cin >> final_score;//read in Final score
	cin >> assign_score;//read in Assignments score

	test1_score = test1_score * 0.15;//multiply the value of test1_score by 0.15
	test2_score = test2_score * 0.15;//multiply the value of test2_score by 0.15
	final_score = final_score * 0.40;//multiply the value of final_score by 0.40
	assign_score = assign_score * 0.30;//multiply the value of assign_score by 0.30

	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	total_score = test1_score + test2_score + final_score + assign_score;

	cout << "Your Total score is: " << total_score << endl;

	return 0;
}
Last edited on
Topic archived. No new replies allowed.