Help me with my assignment!

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2006
Posts: 3
Reputation: Dashing Boy is an unknown quantity at this point 
Solved Threads: 0
Dashing Boy Dashing Boy is offline Offline
Newbie Poster

Help me with my assignment!

 
0
  #1
May 30th, 2006
Hi,

I have given a assignment to make a program using arrays input match played and win for five cricket teams in the month of April then give the ratings of the teams like “CITY BANK CRICKET RATING�.

So far I have done this:
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main (void)
  4. {
  5. int a,ab[5,2],ad[5],b;
  6. float ac[5],ae[5];
  7. clrscr();
  8. printf("\nfive teams are: \n1.pakisatan\n2.south africa\n3.india\n4.australia\n5.england");
  9. for (a=0;a<=4;a++)
  10. {
  11. if (a==0)
  12. printf("\n\t\tpakistan");
  13. if (a==1)
  14. printf("\n\t\tsouth africa");
  15. if (a==2)
  16. printf("\n\t\tindia");
  17. if (a==3)
  18. printf("\n\t\taustralia");
  19. if (a==4)
  20. printf("\n\t\tengland");
  21. printf("\nmatch played: ");
  22. scanf("%d",&ab[a,0]);
  23. printf("\nwin: ");
  24. scanf("%d",&ab[a,1]);
  25. ac[a]=(ab[a,1]*100.0)/ab[a,0];
  26. ae[a]=ac[a];
  27. printf("\nwin percent is %.2f",ac[a]);
  28. }
  29. for (a=0;a<=4;a++)
  30. {
  31. ad[a]=0;
  32. for (b=0;b<=4;b++)
  33. {
  34. if (ac[a]<ac[b])
  35. ad[a]=b;
  36. }
  37. ac[ad[a]]=0;
  38. }
  39. clrscr();
  40. printf("\t\tCITY BANK CRICKET RATINGS");
  41. printf("\n\t\t________________________");
  42. printf("\n\n\n\t\tteams\t\twin percent");
  43. for (a=0;a<=4;a++)
  44. {
  45. if (ad[a]==0)
  46. printf("\n%d\t\tpakistan\t\t\t%.2f",a+1,ae[ad[a]]);
  47. if (ad[a]==1)
  48. printf("\n%d\t\tsouth africa\t\t%.2f",a+1,ae[ad[a]]);
  49. if (ad[a]==2)
  50. printf("\n%d\t\tindia\t\t\t%.2f",a+1,ae[ad[a]]);
  51. if (ad[a]==3)
  52. printf("\n%d\t\taustralia\t\t%.2f",a+1,ae[ad[a]]);
  53. if (ad[a]==4)
  54. printf("\n%d\t\tengland\t\t%.2f",a+1,ae[ad[a]]);
  55. }
  56. getch();
  57. }
But there is something wrong sorting, I couldn't figured out yet. I tried everything I could but no result.

Please Please tell me what should I do to make it work.

Waiting for reply.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Help me with my assignment!

 
0
  #2
May 30th, 2006
> void main (void)
main returns an int

> int a,ab[5,2],ad[5],b;
A 2D array would be
int ab[5][2];

Likewise, accessing it would be
scanf("%d",&ab[a][0]);
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3
Reputation: Dashing Boy is an unknown quantity at this point 
Solved Threads: 0
Dashing Boy Dashing Boy is offline Offline
Newbie Poster

Re: Help me with my assignment!

 
0
  #3
May 30th, 2006
Originally Posted by Salem
> void main (void)
main returns an int

> int a,ab[5,2],ad[5],b;
A 2D array would be
int ab[5][2];

Likewise, accessing it would be
scanf("%d",&ab[a][0]);
Thanks for replying.

I tried doing what you said but still no improvement.

Please help me out!
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC