944,118 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 896
  • C RSS
May 30th, 2006
0

Help me with my assignment!

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dashing Boy is offline Offline
3 posts
since May 2006
May 30th, 2006
0

Re: Help me with my assignment!

> 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]);
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
May 30th, 2006
0

Re: Help me with my assignment!

Quote 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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dashing Boy is offline Offline
3 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Add-In is un-known from within its button obj
Next Thread in C Forum Timeline: Quick Sort Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC