hello guys...i'm rookie in C...just starting out...:$
Well...the program i was trying to write was make a series like:
0
10
010
1010
.
.
.
Now i wrote a program. But it's kinda behaving weird.
Let me show your the output:
enter the no of rows you want: 4
0
10
010
1010
Do you want to check it again?y/n: wrong instuction,retry
Do you want to check it again?y/n:
if 'y' it's starting again, if 'n' then getting out...for others showing 'wrong instuction'
So you can see the 'wrong instuction,retry' is geting added with 'Do you want to check it again?y/n:' !!!!:-/...then again asking 'Do you want to check it again?y/n:'
here's the code:
#include <stdio.h>
#include <conio.h>
int main(){
int i,i2,row,mod;
char ch;
while(ch){
printf("enter the no of rows you want:");
scanf("%d",&row);
for(i=0;i<=row-1;i++)
{
mod= i%2;
for(i2=0;i2<=i;i2++){
printf("%d",mod);
if(mod==0){mod=1;}
else{mod=0;}
}
printf("\n");
}
while(ch)
{
printf("\rDo you want to check it again?y/n: ");
scanf("%c",&ch);
if(ch=='n')
{
printf("\nGoodbye");
getch();clrscr();exit();
}
else if(ch!='y')
{
textcolor(RED+BLINK);
cprintf("wrong instuction,retry\n");
textcolor(7);
}
else
{ break; }
}
}
return 0;
}
and here i tried again changing the infinite loop:
#include <stdio.h>
#include <conio.h>
int main()
{
int i,i2,row,mod;
char ch,temp=1;
while(temp==1)
{
printf("enter the no of rows you want:");
scanf("%d",&row);
for(i=0;i<=row-1;i++)
{
mod= i%2;
for(i2=0;i2<=i;i2++)
{
printf("%d",mod);
if(mod==0){mod=1;}
else{mod=0;}
}
printf("\n");
}
temp=0;
while(temp==0)
{
printf("\rDo you want to check it again?y/n: ");
scanf("%c",&ch);
switch(ch)
{
case 'n':
{
printf("\nGoodbye");
getch();clrscr();exit();
}
case 'y':
{
temp=1;break;
}
default:
{
textcolor(RED+BLINK);
cprintf("wrong instuction,retry\n");
textcolor(7);
}
}
}
}
return 0;
}
am i missing something?? :confused:I'm really worried coz i think i got some misconception somewhere, which i need to fix.