using ceil and floor

Pages: 12
You've got lost in the logic. Your code above says:

First, check to see if percentage is the same as 85, and THEN, if it is, floor it.

Do you see how that's completely back to front?

You need to floor it first, and THEN check to see if the new value is the same as 85.
Last edited on
When I do it this way it still doesnt work
Last edited on


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <cmath>

using std::cout;
using std::endl;
int main()
{
  double percentage;
 
  std::cout << "Enter percentage (e.g. 58.974)" << std::endl;
  std::cin >> percentage;

  percentage = floor(percentage);


if (percentage >= 95)
	{
		cout << "You got an A" << endl;
	}
	else if (percentage >= 90 && percentage < 95)
	{
		cout << "You got a A-" << endl;
	}
	else if (percentage > (85) && percentage < 90)
	{
		cout << "You got a B+" << endl;
	}
	else if (percentage == 85)
	{
		cout << "You got a B" << endl;
	}
	else if (percentage >= 80 && percentage < 85)
	{
		cout << "You got a B-" << endl;
	}
	else if (percentage > 75 && percentage < 80)
	{
		cout << "You got a C+" << endl;
	}
	else if (percentage == 75)
	{
		cout << "You got a C" << endl;
	}
	else if (percentage >= 70 && percentage < 75)
	{
		cout << "You got a C-" << endl;
	}
	else if (percentage > 65 && percentage < 70)
	{
		cout << "You got a D+" << endl;
	}
	else if (percentage == 65)
	{
		cout << "You got a D" << endl;
	}
	else if (percentage >= 60 && percentage < 65)
	{
		cout << "You got a D-" << endl;
	}
	else
	{
		cout << "You got a F" << endl;
	}

 return 0;
}
Topic archived. No new replies allowed.
Pages: 12