From: Martin Ambuhl Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie(please Help) Date: Thu, 12 Nov 1998 05:16:25 -0500 Content-Transfer-Encoding: 7bit References: <7Zo22.346$ee1 DOT 498299 AT newsr2 DOT u-net DOT net> Organization: Nocturnal Aviation X-Posted-Path-Was: not-for-mail X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Lines: 104 NNTP-Posting-Host: 1cust31.tnt14.nyc3.da.uu.net X-ELN-Date: Thu Nov 12 02:25:04 1998 X-Mailer: Mozilla 4.5 [en] (Win95; I) Message-ID: <364AB579.D10B5F1E@earthlink.net> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Jase wrote: > > Can someone please tell me where i am going wrong with this program i know > its crap but its for college. > > thanks > jase AT lionst DOT u-net DOT com Apart from not formatting your text decently and using nonstandard (and occasionally illegal) C, you're mainly making this too hard. Notice how much cleaner (and safer) is: /* Program to produce multiplication tables */ #include #include #include int main(void) { int table, lines, count; char buf[128]; while (1) { while (1) { printf("Enter a multiplier in the range [0,12]: "); fflush(stdout); if (!fgets(buf, sizeof buf, stdin) || sscanf(buf, "%d", &table) != 1) exit(EXIT_FAILURE); if (table <= 12 && table >= 0) break; } while (1) { printf("Enter the number of lines in the range [0,12]: "); fflush(stdout); if (!fgets(buf, sizeof buf, stdin) || sscanf(buf, "%d", &lines) != 1) exit(EXIT_FAILURE); if (lines <= 12 && lines >= 0) break; } printf("\tThe %d times table\n", table); for (count = 0; count <= lines; count++) printf("%2d * %2d= %4d\n", count, table, count*table); printf("Do you want another go [y or n]: "); fflush(stdout); if (!fgets(buf, sizeof buf, stdin) || tolower(buf[0] != 'y')) break; } return 0; } ====== [jase's original code] ====== > > /*Progran to produce multiplacation tables*/ > #include > #include > void main(void) > { > float table=0,lines=0,count,total=0; > char end; > do > { > printf("Enter the times table 0-12 "); > scanf("%f",&table); /*get times table from user*/ > while(table>12 || table<0) > { > printf("\nYou must enter a number between 0-12 > "); > scanf("%f",&table); > } > > printf("\nEnter the number of lines 0-12 "); > scanf("%f",&lines); > while(lines>12 || lines<0) > { > printf("\nYou must enter a number between 0-12 > "); > scanf("%f",&lines); > } > clrscr(); > printf("\tThe %.3f times table\n",table); > for(count=0; count<=lines; > count++) > { > total=count*table; > printf("\n%.1f * %.1f= > %.1f\n",count,table,total); > } > printf("Do you want another > go y or n \n"); > fflush(stdin); > scanf("%d",&end); > table=0; > lines=0; > }while(end=='y'); > } -- Martin Ambuhl (mambuhl AT earthlink DOT net) Note: mambuhl AT tiac DOT net will soon be inactive