473,803 Members | 3,758 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding the lowest score

namcintosh
67 New Member
First of all, here is my program:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio>
  3. using namespace std;
  4.  
  5. //Function prototype
  6. void getscore(int&, int&, int&, int&, int&);
  7. void findLowest (int, int, int, int, int, int);
  8. int main()
  9. {
  10.         int LO, score1, score2, score3, score4, score5;
  11.  
  12.         getscore (score1, score2, score3, score4, score5);
  13.         findLowest(LO, score1, score2, score3, score4, score5);
  14.  
  15.         getch();
  16.         return 0;
  17. }
  18.  
  19.  
  20.  
  21. void getscore (int &score1, int &score2, int &score3, int &score4, int &score5)
  22. {
  23.         cout << "Enter first score: ";
  24.         cin  >> score1;
  25.         cout << "Enter second score: ";
  26.         cin  >> score2;
  27.         cout << "Enter third score: ";
  28.         cin  >> score3;
  29.         cout << "Enter fourth score: ";
  30.         cin  >> score4;
  31.         cout << "Enter fifth score: ";
  32.         cin  >> score5;
  33. }
  34.  
  35. void findLowest(int LO, int score1, int score2, int score3, int score4, int score5)
  36. {
  37.  
  38.         LO = 1000;
  39.  
  40.         if (score1 < LO)
  41.         {
  42.             LO = score1;
  43.             cout << "The lowest score is" <<LO <<endl;
  44.         }
  45.  
  46.         else if (score2 < LO)
  47.         {
  48.             LO = score2;
  49.             cout << "The lowest score is" <<LO <<endl;
  50.         }
  51.         else if (score3 < LO)
  52.         {
  53.             LO = score3;
  54.             cout << "The lowest score is" <<LO <<endl;
  55.         }
  56.         else if (score4 < LO)
  57.         {
  58.             LO = score4;
  59.             cout << "The lowest score is" <<LO <<endl;
  60.         }
  61.         else if (score5 < LO)
  62.         {
  63.             LO = score5;
  64.             cout << "The lowest score is" <<LO <<endl;
  65.         }
  66. }
Okay, I got one part of the program to work right. The only problem is finding the lowest score.

I declared some if/else if statements and also assigned LO to a large number, such as 1000. Here's my output:

Expand|Select|Wrap|Line Numbers
  1. Enter first score: 100
  2. Enter second score: 75
  3. Enter third score: 55
  4. Enter fourth score: 100
  5. Enter fifth score: 85
  6. The lowest score is100
Do you see what I mean? It declares 100 as the lowest number. Why is it doing that?
Apr 20 '07
54 6640
ilikepython
844 Recognized Expert Contributor
OK, so how can I get it to return a value
From the function? You add "return s;" at the end of the function.
Apr 23 '07 #21
Savage
1,764 Recognized Expert Top Contributor
Yup.

And then when u call the function call it like:

int s;//this is in main

s=findLowest(sc ore1,score2,sco re3,score4,scor e5);

and also:
function must be of :int,float...al l those types except void which can't return anything.

Savage
Apr 23 '07 #22
namcintosh
67 New Member
Yup.

And then when u call the function call it like:

int s;//this is in main

s=findLowest(sc ore1,score2,sco re3,score4,scor e5);

and also:
function must be of :int,float...al l those types except void which can't return anything.

Savage
Okay, thanks!
Apr 23 '07 #23
Savage
1,764 Recognized Expert Top Contributor
Okay, thanks!
U are welcome!!

Savage
Apr 23 '07 #24
namcintosh
67 New Member
U are welcome!!

Savage

Ok, but now I am having problems with the void calcAverage() function. This function should calculate and display the average of the four highest test scores. It should also be called just once by main, and should be passed the five scores.

Now, here s my program so far:

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio>
  3. using namespace std;
  4.  
  5. //Function prototype
  6. void getscore(int&, int&, int&, int&, int&);
  7. int findLowest (int, int, int, int, int, int);
  8. void calcAverage (int)
  9. int main()
  10. {
  11.         int average, score1, score2, score3, score4, score5;
  12.  
  13.         getscore (score1, score2, score3, score4, score5);
  14.         calcAverage (average)
  15.         getch();
  16.         return 0;
  17. }
  18.  
  19.  
  20.  
  21. void getscore (int &score1, int &score2, int &score3, int &score4, int &score5)
  22. {
  23.         cout << "Enter first score: ";
  24.         cin  >> score1;
  25.         cout << "Enter second score: ";
  26.         cin  >> score2;
  27.         cout << "Enter third score: ";
  28.         cin  >> score3;
  29.         cout << "Enter fourth score: ";
  30.         cin  >> score4;
  31.         cout << "Enter fifth score: ";
  32.         cin  >> score5;
  33. }
  34.  
  35. void calcAverage (int average)
  36. {
  37.         int average;
  38. }
  39. int findLowest(int small, int score1, int score2, int score3, int score4, int score5)
  40. {
  41.         small =score1;
  42.  
  43.         if(small>score2)
  44.         {
  45.         small=score2;
  46.         }
  47.         if(small>score3)
  48.         {
  49.         small=score3;
  50.         }
  51.         if(small>score4)
  52.         {
  53.         small=score4;
  54.         }
  55.         if(small>score5)
  56.         {
  57.         small=score5;
  58.         }
  59.         return small; 
  60. }
I know how to calculate the average: Average = ((score 1 + score 2 + score 3 + score 4 + score5 -SMALL))/4

I just don't know how to put it in the program
Apr 23 '07 #25
sicarie
4,677 Recognized Expert Moderator Specialist
This function should calculate and display the average of the four highest test scores. It should also be called just once by main, and should be passed the five scores.
Expand|Select|Wrap|Line Numbers
  1. void calcAverage (int)
  2. int main()
  3. {
  4.         calcAverage (average)
  5. }
  6. void calcAverage (int average)
  7. {
  8.         int average;
  9. }
  10.  
I know how to calculate the average: Average = ((score 1 + score 2 + score 3 + score 4 + score5 -SMALL))/4

I just don't know how to put it in the program
I snipped the above for brevity. So reading what the function should do, what do you need to pass to it, and where do you put that? Once you have those, they are considered local variables, so your implementation should be ready to work.

(If you're getting stuck on the function declarations/implementations , look at the example of the last one you just made. What did the outline say for what you needed to do to create it, and then how did you create it - where did you put the things it said.) I'm pretty sure you can figure this one out - just look at the one you've already created as an example.
Apr 23 '07 #26
namcintosh
67 New Member
Okay, this is what I came up with:


Expand|Select|Wrap|Line Numbers
  1. void getscore(int&, int&, int&, int&, int&);
  2. int findLowest (int, int, int, int, int, int);
  3. void calcAverage (int)
  4. int main()
  5. {
  6.         int average, score1, score2, score3, score4, score5;
  7.  
  8.         getscore (score1, score2, score3, score4, score5);
  9.         calcAverage (average)
  10.         getch();
  11.         return 0;
  12. }
  13.  
  14.  
  15.  
  16. void getscore (int &score1, int &score2, int &score3, int &score4, int &score5)
  17. {
  18.         cout << "Enter first score: ";
  19.         cin  >> score1;
  20.         cout << "Enter second score: ";
  21.         cin  >> score2;
  22.         cout << "Enter third score: ";
  23.         cin  >> score3;
  24.         cout << "Enter fourth score: ";
  25.         cin  >> score4;
  26.         cout << "Enter fifth score: ";
  27.         cin  >> score5;
  28. }
  29.  
  30. void calcAverage (int average)
  31. {
  32.         int average;
  33.         average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
  34.  
  35.         cout << average;
  36. }
  37. int findLowest(int small, int score1, int score2, int score3, int score4, int score5)
  38. {
  39.         small =score1;
  40.  
  41.         if(small>score2)
  42.         {
  43.         small=score2;
  44.         }
  45.         if(small>score3)
  46.         {
  47.         small=score3;
  48.         }
  49.         if(small>score4)
  50.         {
  51.         small=score4;
  52.         }
  53.         if(small>score5)
  54.         {
  55.         small=score5;
  56.         }
  57.         return small; 
  58. }
But now, when I try to run the program, I am getting a declaration syntax error (see bold) Why is it doing that???
Apr 24 '07 #27
Savage
1,764 Recognized Expert Top Contributor
[quote=namcintos h]Okay, this is what I came up with:



void calcAverage (int)


It looks like u are missing semicolumn.

Savage
Apr 24 '07 #28
Ganon11
3,652 Recognized Expert Specialist
It looks like you are missing a semicolon after the declaration.
Apr 24 '07 #29
Savage
1,764 Recognized Expert Top Contributor
I can't belive that i writed semicolumn instead of semicolon.LOL

Savage
Apr 24 '07 #30

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

Similar topics

4
3805
by: Han | last post by:
Determining the pattern below has got my stumped. I have a page of HTML and need to find all occurrences of the following pattern: score=9999999999&amp; The number shown can be 5-10 characters in length. I would like to extract only the number, stripping off the "score=" and "&amp;".
4
4730
by: Porthos | last post by:
Hi All, I'm trying to find the minimum value of a set of data (see below). I want to compare the lengths of these attribute values and display the lowest one. This would be simple if I could re-assign values to a variable, but from what I gather I can't do that. How do I keep track of the lowest value as I loop through? My XSL document only finds the length of each string and prints it out (for now). I can write a template
3
6944
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE t1.id < t2.id
6
1991
by: Matt Chwastek | last post by:
Anyone who can help, I am curretnly attempting to write some code that will allow iteration using a vector<intfrom the highest possilbe degree of a combination of ones & zeros (111, 110, 101, 011, 100, 010, 001, 000). The ordering of element containing the same number of ones is not important to the code, just the fact that the highest number of ones are iterated first. I would prefer not to use a binary string as eventually the
2
2022
sonic
by: sonic | last post by:
Does anyone know what I can do to this function to get it to drop the lowest value? Thanks for any insight. void sort(double* score, int size) { int startScan; int minIndex; double minValue;
5
6330
by: davenet | last post by:
Hi, I'm new to Python and working on a school assignment. I have setup a dictionary where the keys point to an object. Each object has two member variables. I need to find the smallest value contained in this group of objects. The objects are defined as follows:
1
3411
by: Flanders | last post by:
I have developed a small arcade game with the help of a few VB books. A scoring system was implemented in the design of the game but I as hoping that some one would be able to instruct me on how display the score at the end of the game. At the moment when a player finishes the game I have a window displaying "Puzzle Solved." If I could display the players score under this in the same window would be great. This is a quick copy and paste...
2
1830
by: marybrown | last post by:
i will write the complete problem i am facing. Here is the input file i am using. sxoght: #query hit score probability qstart qend qorientation tstart tend matches mismatches gapOpening gaps @SNPSTER4_104_308EFAAXX:1:1:1694:128 GGGATAAGAGAGGTGCATGTTGGTATTTAAGGTAGT 1 alignment(s) -- reports limited to 10 alignment(s) sxoght: SNPSTER4_104_308EFAAXX:1:1:1694:128 gi|122939163|ref|NM_000165.3| -10 ...
3
8904
by: hamishmcgee | last post by:
Ok, so for a project at university I have to create a High Score table in C++ with Visual Studio. Just to let you know this is my first year at university and also my first time ever learning C++. So far I have a working menu, which lets you enter in your name, highscore and date which then gets saved to a file and is outputted via another option on the menu. I had a lot of trouble gettin the user info to save to a file in the first place, then...
0
9564
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10292
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.