Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Programming in C - Kinda stuck (http://www.go4expert.com/forums/programming-c-kinda-stuck-t1611/)

 PEANUTS 13Oct2006 22:26

Programming in C - Kinda stuck

The idea:
Using looping methods and the IF constrcut to print the numbers between 1 and 10 along with an idications of whether each is even or odd. Like this

1 is odd
2 is even
3 is odd

Using C

My attempt:

/* Name:

Cameron Owen
CIC Y1 G1
Software Development
Mathmatics

*/
Code:

```#include <stdio.h> void main (void) { int iCount;                    //decalered integar variable iCount=1;                                        //assigning 1 to iCount clrscr();                                 do{                                 printf("%d",iCount);                                         if(iCount, "%/2==0");                                         printf ("EVEN\n");                                         else                                         printf ("ODD\n");                                         iCount++;                                   }while(iCount<11); getch(); }```
i understand the basic idea for C but require further assisance. This only gives one error. Else is misplaced.
I know there are other ways to do this without the need to use a maths division but that would only work for the numbers i choose.

My idea is, if a number is divisable by 2 and gives a remainder 0. Then its even
If a number is divisable by 2 and gives a remiander 1. It is odd

Many thanks if you help me on this,

Cameron

 shabbir 15Oct2006 12:39

Re: Programming in C - Kinda stuck

You have posted it as an Article under the Article / Source code section. I have moved it to the Queries and Discussion forum.

Also please use the bbcode for the code snippets you put in.

 shabbir 15Oct2006 12:41

Re: Programming in C - Kinda stuck

Just replace the dowhile loop with the following

Code:

```do{         printf("%d",iCount);                 if(iCount%2==0)                 printf ("EVEN\n");         else                 printf ("ODD\n");                 iCount++; }while(iCount<11);```

 All times are GMT +5.5. The time now is 12:46.