Hello World, I am new to c++ and can you help me with this program. Is says that there needs to be a primary expression before '>=' token on line 21.
I am using Dev-CPP
/* summer.c
* ---------------
* This program reads a month number and checks if it
* is in the months of summer.
*/
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
main()
{
int month;
printf ("This program reads a month number and checks if it is in the months of summer.\n");
printf ("Enter a month number.\n");
switch (month)
{
case 6: printf ("June is in summer.\n"); break;
case 7: printf ("July is in summer.\n"); break;
case 8: printf ("August is in summer.\n"); break;
case (>=1) && (<=12): printf ("%d is not in summer.\n", month); break;
default: printf ("%d is out of range.\n", month); break;
}
getchar();
}
/* summer.c
* ---------------
* This program reads a month number and checks if it
* is in the months of summer.
*/
#include <stdio.h>
#include "simpio.h"
#include "genlib.h"
main()
{
int month;
printf ("This program reads a month number and checks if it is in the months of summer.\n");
printf ("Enter a month number.\n");
month = GetInteger();
switch (month)
{
case 1: printf ("January is not in summer.\n"); break;
case 2: printf ("February is not in summer.\n"); break;
case 3: printf ("March is not in summer.\n"); break;
case 4: printf ("April is not in summer.\n"); break;
case 5: printf ("May is not in summer.\n"); break;
case 6: printf ("June is not in summer.\n"); break;
case 7: printf ("July is in summer.\n"); break;
case 8: printf ("August is in summer.\n"); break;
case 9: printf ("September is not in summer.\n"); break;
case 10: printf ("October is not in summer.\n"); break;
case 11: printf ("November is not in summer.\n"); break;
case 12: printf ("December is not in summer.\n"); break;
default: printf ("%d is out of range.\n"); break;
}
getchar();
}
That should work, though you could also just run all the case statements together.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
switch(x) {
case 1:
// do stuff
break;
case 2:
// do stuff
break;
case 3:
case 4:
case 5:
// do same stuff for some cases
break;
default:
// do stuff
}