Help finding numbers

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 1
Reputation: kafkas is an unknown quantity at this point 
Solved Threads: 0
kafkas kafkas is offline Offline
Newbie Poster

Help finding numbers

 
0
  #1
Jan 8th, 2008
I need to find the 5 middle numbers in the center(example: 2 3 4 5 6 7 8, the middle numbers are 3 4 5 6 7, remove+subtract largest and smallest numbers), I have tried many ways but have not succeeded. Can anyone please help me?

  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <ctype.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. float findMiddleOne(float,float,float,float,float,float,float);
  9. float findFirst(float,float,float,float,float,float,float);
  10. float findLast(float,float,float,float,float,float,float);
  11.  
  12. int main ()
  13. {
  14. string name;
  15. float score1,score2,score3,score4,score5,score6,score7,ttlscore=0;
  16. float firstlowest=0;
  17. float lastlargest=0;
  18. float difficulty;
  19. cout << "Enter the divers name: ";
  20. getline (cin,name);
  21. cout << "Enter the degree of difficulty for "<<name<<"'s dive: ";
  22. cin >> difficulty;
  23. while (difficulty<1.2 ||difficulty>3.8)
  24. {
  25. cout << "Such difficulty does not exist, please try again: ";
  26. cin >> difficulty;
  27. }
  28. cout<<"Enter the seven judges' scores"<<endl;
  29. cout<<"First score: ";
  30. cin >> score1;
  31. while (score1<0||score1>10)
  32. {
  33. cout << "Wrong number, please try again: ";
  34. cin >> score1;
  35. }
  36. cout <<"Second score: ";
  37. cin >> score2;
  38. while (score2<0||score2>10)
  39. {
  40. cout << "Wrong number, please try again: ";
  41. cin >> score2;
  42. }
  43. cout <<"Third score: ";
  44. cin >> score3;
  45. while (score3<0||score3>10)
  46. {
  47. cout << "Wrong number, please try again: ";
  48. cin >> score3;
  49. }
  50. cout<<"Fourth score: ";
  51. cin >> score4;
  52. while (score4<0||score4>10)
  53. {
  54. cout << "Wrong number, please try again: ";
  55. cin >> score4;
  56. }
  57. cout <<"Fifth score: ";
  58. cin >> score5;
  59. while (score5<0||score5>10)
  60. {
  61. cout << "Wrong number, please try again: ";
  62. cin >> score5;
  63. }
  64. cout <<"Sixth score: ";
  65. cin >> score6;
  66. while (score6<0||score6>10)
  67. {
  68. cout << "Wrong number, please try again: ";
  69. cin >> score6;
  70. }
  71. cout <<"Seventh score: ";
  72. cin >> score7;
  73. while (score7<0||score7>10)
  74. {
  75. cout << "Wrong number, please try again: ";
  76. cin >> score7;
  77. }
  78. firstlowest = findFirst(score1,score2,score4,score4,score5,score6,score7);
  79. lastlargest = findLast(score1,score2,score4,score4,score5,score6,score7);
  80. ttlscore = (score1+score2+score3+score4+score5+score6+score7-firstlowest-lastlargest)*difficulty*0.6;
  81. cout << name <<"'s total score is "<<ttlscore<<endl;
  82.  
  83. cin >> ttlscore;
  84. return 0;
  85. }
  86.  
  87. float findFirst(float mid1,float mid2,float mid3,float mid4,float mid5,float mid6, float mid7)
  88. {
  89. float firstlowest;
  90. firstlowest = mid1;
  91. if (mid2 < firstlowest)
  92. firstlowest=mid2;
  93. if (mid3 < firstlowest)
  94. firstlowest=mid3;
  95. if (mid4 < firstlowest)
  96. firstlowest=mid4;
  97. if (mid5 < firstlowest)
  98. firstlowest=mid5;
  99. if (mid6 < firstlowest)
  100. firstlowest=mid6;
  101. if (mid7 < firstlowest)
  102. firstlowest=mid7;
  103. return firstlowest;
  104. }
  105. float findLast(float midd1,float midd2,float midd3,float midd4,float midd5,float midd6, float midd7)
  106. {
  107. float lastlargest;
  108. lastlargest = midd1;
  109. if (midd2 > lastlargest)
  110. lastlargest=midd2;
  111. if (midd3 > lastlargest)
  112. lastlargest=midd3;
  113. if (midd4 > lastlargest)
  114. lastlargest=midd4;
  115. if (midd5 > lastlargest)
  116. lastlargest=midd5;
  117. if (midd6 > lastlargest)
  118. lastlargest=midd6;
  119. if (midd7 > lastlargest)
  120. lastlargest=midd7;
  121. return lastlargest;
  122. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,406
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1467
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help finding numbers

 
0
  #2
Jan 9th, 2008
you want to work with arrays. First create an array of 5 integers
int array[] = {1,2,3,4,5};
Now its simple. The middle three numbers are array[1], array[2], and array[3].

Next, to get the largest and smallest numbers, just create a loop and check each array element
  1. int largest = array[1];
  2. int smallest = array[1];
  3. for(int i = 1; i < 4; i++)
  4. {
  5. if( largest < array[i])
  6. largest = array[i];
  7. // now do the same test for smallest
  8. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Help finding numbers

 
0
  #3
Jan 9th, 2008
Are the numbers in that array in order?
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC