Need help please

Hey guys,
My program asks for a physics mark and outputs the mark as a percentage. I'm stuck on making sure that the mark is not below 0 or above 100. I've tried using a for loop, but that doesn't do the trick.

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

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
	int physics;

	cout << "Please enter your mark for physics: ";
	cin >> physics;
	cout << "\n";

	if (physics > 100 || physics < 0);
	{
		for (;;) 
		{
			cout << "Data value is out of range, please try again.";  
			cout << "\n";
			cout << "Please enter your mark for physics: ";
			cin >> physics;
			cout << "\n";

			if (100 >= physics || physics >= 0);
			{
				break;
			}
		}
		
	}

	if (100 >= physics || physics >= 0);
	{
		cout << "\n";
		cout << "Your physics mark is: " << physics << "%";
		cout << "\n";
	}
	system("pause");
	return 0;
}
1. See lines 25 and 33.
OR is ||
AND is &&


2. See lines 15 and 33 - remove those semicolons at the ends of the lines or the if blocks will actually be empty and the following lines will always run.
Last edited on
Topic archived. No new replies allowed.