473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4.  
  5. void main()
  6. {
  7. struct prod{
  8. int i3,i5,i7,a8,a10,fx6,fx8;
  9. float sum;
  10. } cpu;
  11. struct customer{
  12. char id[15];
  13. struct prod cpu;
  14. } cst[30][50];
  15. int i=0,j=0,ti3[30],ti5[30],ti7[30],ta8[30],ta10[30],tfx6[30],tfx8[30],ti=1,tj=1;
  16. float nsum=0,xsum[50],tsum=0;
  17. char ss,x;
  18. clrscr();
  19. printf("\n 1 - Intel Core I3     3599");
  20. printf("\n 2 - Intel Core I5     5599");
  21. printf("\n 3 - Intel Core I7     7599");
  22. printf("\n 4 - AMD A8     3749");
  23. printf("\n 5 - AMD A10 4999");
  24. printf("\n 6 - AMD FX6 5229");
  25. printf("\n 7 - AMD FX8 7499");
  26. printf("\n 0 - Next Customer\n");
  27.  
  28. getch();
  29. for(i=0;i<ti;i++,ti++)
  30. {
  31. tsum=0; fflush(stdin); xsum[i]=0;
  32. printf("Customer# %d : \n",i+1);
  33. if(i>0)
  34. {
  35. printf("Finish? [Y/N]"); x=getche();
  36. if(x=='y'||x=='Y')
  37. ti-=1;
  38. else
  39. {
  40. clrscr();
  41. printf("Customer# %d : \n",i+1);
  42. }
  43. }
  44.  
  45. printf("\tID : "); fflush(stdin); gets(cst[i][j].id);
  46.  
  47. for(j=0;j<tj;j++,tj++)
  48. {
  49.  
  50. printf("\tProduct #%d",j+1);
  51. R:
  52. printf("Choose : "); fflush(stdin); ss=getche();
  53.  
  54. if(ss=='1')
  55. {tsum+=3599; ti3[i]+=1; cst[i][j].cpu.i3=ti3[i];}
  56. else if(ss=='2')
  57. {tsum+=5599; ti5[i]+=1; cst[i][j].cpu.i5=ti5[i];}
  58. else if(ss=='3')
  59. {tsum+=7599; ti7[i]+=1; cst[i][j].cpu.i7=ti7[i];}
  60. else if(ss=='4')
  61. {tsum+=3749; ta8[i]+=1; cst[i][j].cpu.a8=ta8[i];}
  62. else if(ss=='5')
  63. {tsum+=4999; ta10[i]+=1; cst[i][j].cpu.a10=ta10[i];}
  64. else if(ss=='6')
  65. {tsum+=5229; tfx6[i]+=1; cst[i][j].cpu.fx6=tfx6[i];}
  66. else if(ss=='7')
  67. {tsum+=7499; tfx8[i]+=1; cst[i][j].cpu.fx8=tfx8[i];}
  68. else if(ss=='0')
  69. {tj-=1;}
  70. else
  71. goto R;
  72.  
  73.  
  74.  
  75. cst[i][j].cpu.sum=tsum;
  76.  
  77. fflush(stdin);
  78. }
  79. xsum[i]=tsum;
  80. }
  81.  
  82. printf("\n\tPress any key to list... \n");
  83. getch(); clrscr(); j=0;
  84.  
  85. for(i=0;i<ti;i++)
  86. { printf("\n Customer ID %s \n",cst[i][j].id);
  87.  
  88.  
  89. for(j=0;j<tj;j++)
  90. {
  91. if(ti3[i]>0)
  92. {
  93. printf("\nIntel Core i3 [3599] X %d",cst[i][j].cpu.i3);
  94. }
  95. if(ti5[i]>0)
  96. {
  97. printf("\nIntel Core i5 [5599] X %d",cst[i][j].cpu.i5);
  98. }
  99. if(ti7[i]>0)
  100. {
  101. printf("\nIntel Core i7 [7599] X %d",cst[i][j].cpu.i7);
  102. }
  103. if(ta8[i]>0)
  104. {
  105. printf("\nAMD A8 [3749] X %d",cst[i][j].cpu.a8);
  106. }
  107. if(ta10[i]>0)
  108. {
  109. printf("\nAMD A10 [4999] X %d",cst[i][j].cpu.a10);
  110. }
  111. if(tfx6[i]>0)
  112. {
  113. printf("\nAMD FX6 [5299] X %d",cst[i][j].cpu.fx6);
  114. }
  115. if(tfx8[i]>0)
  116. {
  117. printf("\nAMD FX8 [7499] X %d",cst[i][j].cpu.fx8);
  118. }
  119.  
  120.  
  121.  
  122. }
  123. printf ("TOTAL %.2f",cst[i][j].cpu.sum);
  124.  
  125. }
  126.  
  127. printf("\n\n\tOVERALL TOTAL : %.2f\n",xsum[i]);
  128.  
  129. }
Feb 26 '13 #1
1 2099
donbock
2,426 Expert 2GB
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.
Feb 26 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Smith | last post by:
I am having a problem. I am attempting to compile the fte text editor (fte-20020324-common.zip and fte-20020324-src.zip on Redhat linux 8.0. Among the error messages I get is the following:...
0
by: | last post by:
i create a new MFC Project with MFC Application wizard. However when i make attempt to run. A compile error message appear: fatal error C1083: Cannot open include file: 'crtdbg.h': No such file...
2
by: Gustavo | last post by:
After updating Windows 2000 I began to get a weird compile error message: Deleting intermediate files and output files for project 'pp - Win32 Debug'. --------------------Configuration: pp -...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
9
by: JTrigger | last post by:
When I compile my project using the IDE on a development machine it works just fine. When I compile it on the server using csc.exe, I get the following error when I try to bring it up in the web...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
1
by: TARUN | last post by:
Hello All I am Stuck in a silly Problem, as I don't have much experience in Web Technology, so Please Excuse me for raising such a questions. I am creating a logging Page, I used Regular...
0
by: guy | last post by:
I am New to ASP.Net 2.0 . For the last few days I have been writing some simple code . The problem is when I tried to debug my program I got an error message : Compile error message :BC 30451:...
1
by: ft310 | last post by:
I am getting the following message when I compile a program with VB .net 2003. The dependency 'Interop.StdFormat' could not be found. There are three other messages following this: The...
1
by: wur9rxsuzu | last post by:
I'm using numeric on screen keys to goto specifig record. when i type the number for example 1234 and hit on screen enter button it has to goto that record. what is the code to be used inthe "enter"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.