help writing c++ program

Write a C++ program that inputs a number from the keyboard between 0 and 49 and then uses a for or while loop to display every integer that follows the integer that is input and that is evenly divisible by 4. The last number that will be displayed is 100. In other words, if the number you input from the keyboard is 45, your program will output
48 52 56 60 … 92 96 100
Or if your input is 40, your program will output
44 48 52 56 … 92 96 100

Your program does not have to run multiple times. One line of numbers per a.out is sufficient.
Place an error trap in your program that will reject any keyboard inputs < 0 or > 49. Use any wording you wish for the input prompt.

Can someone please help me with this program, having trouble writing it
We won't do your homework.
1
2
3
4
5
6
7
8
9
10
11
12
	int num = 0;

	do{
		scanf_s("%d",&num);
	}while(num < 0 || num > 49);

	while(num<=100){
		if(num%4==0){
			printf("%d",num);
		}
		++num;
	}


pretty simple. practice your modulus it comes in handy.

also wrong forum, this is windows programming, and if you can't
do something like this by now, maybe you should take a different class?
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
#include "iostream"

using namespace std;

int main()
{
	int num;
	while(1){
		cin>>num;
		if	(num>=0 && num<=49)
		{
			while(num<=100)
			{
				if(num%4==0)
				{
					cout<<num<<"  ";
				}
			num++;	
			}
		}
		else
		{
			cout<<"number error!"<<endl;
			break;
		}
	}
	return 0;
}
Topic archived. No new replies allowed.