Help me with my homework pls.

C++ Program for the ff:

*Ask the user to input a number.
*If the number is

< 10 print “Number is less than 10”
< 20 print “Number is less than 20 but greater than 10”
< 30 print “Number is less than 30 but greater than 20”
< 40 print “Number is less than 40 but greater than 30”
< 50 print “Number is less than 50 but greater than 40”
< 50 print “Number is greater than 50”

*Use a loop to repeat this process until the user inputs -1.



Output:

Input a number (-1 to exit): 5
Number is less than 10_
Input a number (-1 to exit): 19
Number is less than 20 but greater than 10.
Input a number (-1 to exit): 25
Number is less than 30 but greater than 20.
Input a number (-1 to exit): 55
Number is greater than 50.
Input a number (-1 to exit): -1
Press any key to continue…
What have you written so far?
Is this the right code for my home work? help me correct it.

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
#include <stdio.h>

int main(void)
{
int a=0;
printf("please enter a number : \n");

scanf("%i",&a);

switch(a)
{
         if (a<=10);
            printf("Number is less than 10");
            break;
         if (a<=20 && a>10);
            printf("Number is less than 20 but greater than 10");
            break;
         if (a<=30 && a>20);
            printf("Number is less than 30 but greater than 20");
            break;
         if (a<=40 && a>30);
            printf("Number is less than 40 but greater than 30");
            break;
         if (a<=49 && a>40);
            printf("Number is less than 50 but greater than 40");
            break;
         if (a>=50);
            printf("Number is greater than 50");
            break;
         
         return 0;
         }
}
Please, do not double post. It clutters forums and spreads attempts to help you. Another thread: http://www.cplusplus.com/forum/beginner/171301/
Topic archived. No new replies allowed.