something worng with my program need help please,,

Reply

Join Date: May 2005
Posts: 4
Reputation: idris is an unknown quantity at this point 
Solved Threads: 0
idris idris is offline Offline
Newbie Poster

something worng with my program need help please,,

 
0
  #1
May 16th, 2005
hi,, the program i made is soppost to reads 3 integers from user and solve the average, the maximum, the minimum and their median value..the problem with the program is that the median section is not working, can u please have a look at it..



  1. #include<stdio.h>
  2.  
  3. main( )
  4. {
  5.  
  6. int item[100];
  7. float a, b, c;
  8. int median_index;
  9. float median;
  10. int count;
  11. float sum;
  12.  
  13.  
  14. printf("Enter your first integer\n");
  15. scanf(" %f", & a);
  16.  
  17. printf("Enter your second integer\n");
  18. scanf(" %f", & b);
  19.  
  20. printf("Enter your third integer\n");
  21. scanf(" %f", & c);
  22.  
  23.  
  24. sum = (a + b + c)/3;
  25.  
  26. for(a=0; a<count; a++){
  27. scanf("%f", &item[a]);
  28. }
  29.  
  30. for(a=1; a<count; a++)
  31. for(b=count-1; b>=a; --b){
  32. if(item[b-1] > item[b]){
  33. c=item[b-1];
  34. item[b-1] = item[b];
  35. item[b]=c;
  36. }
  37. }
  38. median = count/2;
  39. if(count%2 ==1){
  40. printf("There are odd sets of numbers.\n");
  41. median = item[count/2];
  42.  
  43. }
  44. else{
  45. median_index = count/2;
  46. printf("There are even sets of numbers.\n");
  47. median = (item[median_index]+item[median_index-1])/2.0;
  48. }
  49.  
  50.  
  51. for(c=0; c<count; c++){
  52. printf("%f\n", item[c]);
  53.  
  54. }
  55.  
  56. printf("\nThe average is %0.2f\n", sum);
  57. printf("The median is %0.2f\n", median);
  58. if ((a > b) && (a > c))
  59. printf("The maximum %0.2f\n", a);
  60.  
  61. else if ((b> a) && (b> c))
  62. printf("The maximum is %0.2f\n", b);
  63.  
  64. else printf("The maximum is %0.2f\n", c);
  65.  
  66.  
  67. if ((a < b) && (a < c)) printf("The minimum is %0.2f", a);
  68.  
  69. else if ((b < a) && (b < c))
  70. printf("The minimum is %0.2f", b);
  71.  
  72. else printf("The minimum is %0.2f", c);
  73.  
  74.  
  75. return 0;
  76.  
  77.  
  78. }
<< moderator edit: added [code][/code] tags >>


But now, I can't run the program because there are some errors, all saying:

1.C:42: invalid types `int[100][float]' for array subscript
1.C:46: invalid types `int[100][float]' for array subscript
1.C:47: invalid types `int[100][float]' for array subscript
1.C:48: invalid types `int[100][float]' for array subscript
1.C:49: invalid types `int[100][float]' for array subscript
1.C:66: invalid types `int[100][float]' for array subscript

What did I do wrong? Could anybody help me please?

Thank You.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,771
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 308
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: something worng with my program need help please,,

 
0
  #2
May 16th, 2005
You can't use floats for array subscripts.
“The essential notion of a socialist society is force.”
— Milton Friedman
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: idris is an unknown quantity at this point 
Solved Threads: 0
idris idris is offline Offline
Newbie Poster

Re: something worng with my program need help please,,

 
0
  #3
May 16th, 2005
thankz for dat,, i adjusted it..
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: idris is an unknown quantity at this point 
Solved Threads: 0
idris idris is offline Offline
Newbie Poster

Re: something worng with my program need help please,,

 
0
  #4
May 16th, 2005
now the porgram runs but it doesn't go through any of the loops (it only ask the user to enter the 3 integers and after that stops), why do u think dat is?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,771
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 308
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: something worng with my program need help please,,

 
0
  #5
May 16th, 2005
Originally Posted by idris
now the porgram runs but it doesn't go through any of the loops (it only ask the user to enter the 3 integers and after that stops), why do u think dat is?
Because count is some random number?
“The essential notion of a socialist society is force.”
— Milton Friedman
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 4
Reputation: idris is an unknown quantity at this point 
Solved Threads: 0
idris idris is offline Offline
Newbie Poster

Re: something worng with my program need help please,,

 
0
  #6
May 17th, 2005
kool, thankz
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2935 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC