turbo c++ 4.5 crash when compile no error message

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • earthempire
    New Member
    • Feb 2013
    • 1

    turbo c++ 4.5 crash when compile no error message

    I'm a student now learning struct with array turbo c++ 4.5 and it crashed when compile this code no error message just crash.

    is the code wrong or anything please help.


    Code:
    #include<stdio.h>
    #include<conio.h>
    
    
    void main()
    {
    struct prod{
    int i3,i5,i7,a8,a10,fx6,fx8;
    float sum;
    } cpu;
    struct customer{
    char id[15];
    struct prod cpu;
    } cst[30][50];
    int i=0,j=0,ti3[30],ti5[30],ti7[30],ta8[30],ta10[30],tfx6[30],tfx8[30],ti=1,tj=1;
    float nsum=0,xsum[50],tsum=0;
    char ss,x;
    clrscr();
    printf("\n 1 - Intel Core I3	 3599");
    printf("\n 2 - Intel Core I5	 5599");
    printf("\n 3 - Intel Core I7	 7599");
    printf("\n 4 - AMD A8	 3749");
    printf("\n 5 - AMD A10 4999");
    printf("\n 6 - AMD FX6 5229");
    printf("\n 7 - AMD FX8 7499");
    printf("\n 0 - Next Customer\n");
    
    getch();
    for(i=0;i<ti;i++,ti++)
    {
    tsum=0; fflush(stdin); xsum[i]=0;
    printf("Customer# %d : \n",i+1);
    if(i>0)
    {
    printf("Finish? [Y/N]"); x=getche();
    if(x=='y'||x=='Y')
    ti-=1;
    else
    {
    clrscr();
    printf("Customer# %d : \n",i+1);
    }
    }
    
    printf("\tID : "); fflush(stdin); gets(cst[i][j].id);
    
    for(j=0;j<tj;j++,tj++)
    {
    
    printf("\tProduct #%d",j+1);
    R:
    printf("Choose : "); fflush(stdin); ss=getche();
    
    if(ss=='1')
    {tsum+=3599; ti3[i]+=1; cst[i][j].cpu.i3=ti3[i];}
    else if(ss=='2')
    {tsum+=5599; ti5[i]+=1; cst[i][j].cpu.i5=ti5[i];}
    else if(ss=='3')
    {tsum+=7599; ti7[i]+=1; cst[i][j].cpu.i7=ti7[i];}
    else if(ss=='4')
    {tsum+=3749; ta8[i]+=1; cst[i][j].cpu.a8=ta8[i];}
    else if(ss=='5')
    {tsum+=4999; ta10[i]+=1; cst[i][j].cpu.a10=ta10[i];}
    else if(ss=='6')
    {tsum+=5229; tfx6[i]+=1; cst[i][j].cpu.fx6=tfx6[i];}
    else if(ss=='7')
    {tsum+=7499; tfx8[i]+=1; cst[i][j].cpu.fx8=tfx8[i];}
    else if(ss=='0')
    {tj-=1;}
    else
    goto R;
    
    
    
    cst[i][j].cpu.sum=tsum;
    
    fflush(stdin);
    }
    xsum[i]=tsum;
    }
    
    printf("\n\tPress any key to list... \n");
    getch(); clrscr(); j=0;
    
    for(i=0;i<ti;i++)
    { printf("\n Customer ID %s \n",cst[i][j].id);
    
    
    for(j=0;j<tj;j++)
    {
    if(ti3[i]>0)
    {
    printf("\nIntel Core i3 [3599] X %d",cst[i][j].cpu.i3);
    }
    if(ti5[i]>0)
    {
    printf("\nIntel Core i5 [5599] X %d",cst[i][j].cpu.i5);
    }
    if(ti7[i]>0)
    {
    printf("\nIntel Core i7 [7599] X %d",cst[i][j].cpu.i7);
    }
    if(ta8[i]>0)
    {
    printf("\nAMD A8 [3749] X %d",cst[i][j].cpu.a8);
    }
    if(ta10[i]>0)
    {
    printf("\nAMD A10 [4999] X %d",cst[i][j].cpu.a10);
    }
    if(tfx6[i]>0)
    {
    printf("\nAMD FX6 [5299] X %d",cst[i][j].cpu.fx6);
    }
    if(tfx8[i]>0)
    {
    printf("\nAMD FX8 [7499] X %d",cst[i][j].cpu.fx8);
    }
    
    
    
    }
    printf ("TOTAL %.2f",cst[i][j].cpu.sum);
    
    }
    
    printf("\n\n\tOVERALL TOTAL : %.2f\n",xsum[i]);
    
    }
    Last edited by Banfa; Feb 26 '13, 09:49 AM. Reason: Added code tags
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Are you saying the compiler crashed ... or that your program crashed when you tried to run it?
    What do you mean by crash?

    The first thing that jumped out at me is line 5. The main function must return an int, not a void.

    I ought to be able to tell you more after you describe the symptoms of the crash.

    Are you teaching yourself to program or do you have an instructor?

    Your program exhibits some idioms that I'm uncomfortable with. To a certain extent this is a matter of personal style so you can choose to do things your way. I have tried to develop a programming style that encourages me to avoid the kinds of mistakes that I know I tend to make.
    1. Your variable names do not provide clues to what the program is trying to do.
    2. Lines 19-25,etc. I prefer to put newlines at the end of printf'ed strings because some systems use buffered output -- where the characters are not actually sent to the screen until a newline is encountered.
    3. Line 29. The loop ends when i >= ti. You change ti within the loop at lines 29 and 37. Doing so makes it much more difficult to understand what conditions cause your loop to terminate. If your intent is for the loop to terminate if line 37 is ever executed, then it would be much clearer if line 29 were "for (i=0,done=0; !done; i++)" and line 37 were "done = 1;".
    4. Similar comment for tj on lines 47 and 69.
    5. What is the purpose of line 33? Isn't i always greater than 0?
    6. Perhaps replace lines 54,56,58,60,62, 64,66,68,70 with a switch statement.
    7. The goto on line 71 causes execution to skip lines 75-76, the end of loop statements (termination test and increment instructions), and line 50. I would look hard for some way to accomplish your intent without making control flow harder to understand.
    8. You use loop variables i and j as array indices on lines 31,45,55,57,59, 61,63,65,67,75, 79,etc. With the way ti and tj can change, what prevents the user from making your program march right past the end of the arrays? Accessing an array with an invalid index is a good way to make a program crash.

    Comment

    Working...