Can setprecision be used when setting a variable

OK here is the problem. I made a program for school that would give a simple math test. Easy enough. Well what is happening is that I got two random numbers coming up in the division part and that is working great, but the total is per say 1.7898654 . ok thats ok also but when I go to answer the math problem if I put in 1.7898654 then its wrong and the answer display is 1.78987. then if i answer it 1.78987 then it will be 1.7899. I am lost. I am trying to do something like this.

1
2
	total = rand1 / rand2;
	total = setprecision(2);


but am getting this error: 1>.\MathTest.cpp(157) : error C2440: '=' : cannot convert from 'std::_Smanip<_Arg>' to 'double'

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
	cout << "\n\nNow division questions: " << endl;
	cout << "Remember you have to get 10 questions correct to move on." << endl;
	int z = 1;

	while(cor4 < 3)
	{
	rand1 = (rand()%100);
	rand2 = (rand()%10);

	cout << "\nQuestion # " << z << ":" << " \nWhat do " << rand1 << " / " << rand2 << " equal? " << endl;
	cin >> answer;

	total = rand1 / rand2;
	total = setprecision(2);

	if(total == answer)
	{
		cout << "Correct! " << endl;
		cor4 = cor4 += 1;
	}

	else
	{
		cout << "Wrong! " << endl;
		cout << "The correct answer was " << total << endl;
		wor = wor += 1;
	}
	z = ++z;



Now that is the whole code for the multiplication part if anyone has any help. I just knew for sure the setprecision would work but its apparently only for times like

cout << setprecision(2);


Thanks for the help.
setprecision is a stream manipulator so it can be used only with stream.
You can do some tricky things with streams:
1
2
3
stringstream ss;
ss << setprecision(4) << rand1 / rand2;
ss >> total;
So how can i get the total answer to be only so many deciaml points?
Topic archived. No new replies allowed.