473,322 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Finding the lowest score

namcintosh
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 #1
54 6547
sicarie
4,677 Expert Mod 4TB
Your else-if chain only checks to see if the numbers are less than LO, or 1000, and they only do it once, there's no looping, so it only does the first one (100), but doesn't loop back after LO is reset. (If a branch is taken in an if-else statement, the rest of it is disregarded) You should put that in a loop, and you'll have to change your logic a bit - otherwise it will print out each time the loop is executed.
Apr 20 '07 #2
Your else-if chain only checks to see if the numbers are less than LO, or 1000, and they only do it once, there's no looping, so it only does the first one (100), but doesn't loop back after LO is reset. (If a branch is taken in an if-else statement, the rest of it is disregarded) You should put that in a loop, and you'll have to change your logic a bit - otherwise it will print out each time the loop is executed.

Can you please show me in my program where that goes???
Apr 20 '07 #3
sicarie
4,677 Expert Mod 4TB
I tried it with if statements, but all of the numbers printed out as low numbers
Have you tried a while loop? Having it repeat several times, and then exiting only when you're sure it has checked all 4 other values against your lowest?
Apr 20 '07 #4
sicarie
4,677 Expert Mod 4TB
Can you please show me in my program where that goes???
I'd recommend sticking it here:

Expand|Select|Wrap|Line Numbers
  1. void findLowest(int LO, int score1, int score2, int score3, int score4, int score5)
  2. {
  3.  
  4.         LO = 1000;
  5.  
  6.         if (score1 < LO)
  7.         {
  8.             LO = score1;
  9.             cout << "The lowest score is" <<LO <<endl;
  10.         }
  11.  
  12.         else if (score2 < LO)
  13.         {
  14.             LO = score2;
  15.             cout << "The lowest score is" <<LO <<endl;
  16.         }
  17.         else if (score3 < LO)
  18.         {
  19.             LO = score3;
  20.             cout << "The lowest score is" <<LO <<endl;
  21.         }
  22.         else if (score4 < LO)
  23.         {
  24.             LO = score4;
  25.             cout << "The lowest score is" <<LO <<endl;
  26.         }
  27.         else if (score5 < LO)
  28.         {
  29.             LO = score5;
  30.             cout << "The lowest score is" <<LO <<endl;
  31.         }
  32. }
Then you could change the function definition to return an int - if you loop until you're sure and return it, you can print it out in your main, not have to worry about IO in your function.
Apr 20 '07 #5
Have you tried a while loop? Having it repeat several times, and then exiting only when you're sure it has checked all 4 other values against your lowest?
I tried a while loop, but I kept getting an error message
Apr 20 '07 #6
sicarie
4,677 Expert Mod 4TB
I tried a while loop, but I kept getting an error message
What's the error?
Apr 20 '07 #7
What's the error?
It keeps saying that I am missing a brace

Oh, and I tried that code that you gave me, and it's still doing the same thing. Run my program on your computer and you will see what I am talking about.
Apr 20 '07 #8
Savage
1,764 Expert 1GB
You need to use a loop just as sicarie sayed.

LO in call to function is not necsasary and why are u using the largest number instead of smallest,more important is to use a loop like:


int(int score1,int score2,int score3,int score4)
{
int S=score1;//we need to declare one number as smallest
int i=0;//we also need a counter for the loop

//Right here we need a do - while loop wchich will loop until it finds the smallest number(while i<4)

so here goes the loop body:

Expand|Select|Wrap|Line Numbers
  1.       if(score2<S) S=score2,i++;continue;
  2.       if(score3<S) S=score3,i++;continue;
  3.       if(score4<S) S=score4,i++;continue;
This way code is smaller and will execute more faster because all those if-else can realy slow down.

Now lets test it:

score1=20;
score2=15;
score3=8;
score4=13;

S=20;

1)15<20 yes,S=15;

2)15<15 no
8<15 yes,S=8;

3) 15<8 no.
8<8 no.
13<8 no.

As we can see smallest number is 8 which is correct.

Savage
Apr 20 '07 #9
Why are there four scores instead of five??? There should be five scores
Apr 20 '07 #10
Savage
1,764 Expert 1GB
Yes,and I know it.I wish that u learn so I have left one for u!! :D

Savage
Apr 20 '07 #11
Savage
1,764 Expert 1GB
Another thing:

Functions like these are not modular so I would rather use arrays for such function just in case that I feel need for it some time in future.


Savage
Apr 20 '07 #12
Yes,and I know it.I wish that u learn so I have left one for u!! :D

Savage
You have one more what

Is there any way that I can use it doing the if/else if statements
Apr 20 '07 #13
Savage
1,764 Expert 1GB
You have one more what

Is there any way that I can use it doing the if/else if statements
Well,in that case do it like:

S=score1;

Expand|Select|Wrap|Line Numbers
  1. if(s>score2) s=score2;
  2. else if(s>score3) s=score3;
  3.        else if(s>score4) s= score4;
  4.               else s=score5

this approach to reguires a same loop
Apr 20 '07 #14
Well,in that case do it like:

S=score1;

Expand|Select|Wrap|Line Numbers
  1. if(s>score2) s=score2;
  2. else if(s>score3) s=score3;
  3.        else if(s>score4) s= score4;
  4.               else s=score5

this approach to reguires a same loop
Oh. I though that at first all I could do was just declare LOW to be a large number and then do the if/else if statements to test it out. But I guess it didn't work because all of the numbers are smaller than 1000.
Apr 22 '07 #15
Savage
1,764 Expert 1GB
Oh. I though that at first all I could do was just declare LOW to be a large number and then do the if/else if statements to test it out. But I guess it didn't work because all of the numbers are smaller than 1000.
Even if there were number larger than 1000 it would not work as u planed.One more thing:

It can be done without using loop but then it would be done only and only by
using if,not if-else.

If u are intrested/intrigued by this let me know!!!

:D

Savage
Apr 22 '07 #16
Even if there were number larger than 1000 it would not work as u planed.One more thing:

It can be done without using loop but then it would be done only and only by
using if,not if-else.

If u are intrested/intrigued by this let me know!!!

:D

Savage
Oh, why Savage, please let me know. I am very interested. :-)
Apr 23 '07 #17
Savage
1,764 Expert 1GB
Glad to hear that!!

So here we go:

Start is the same:

int S=score1;

now to the important part:

Expand|Select|Wrap|Line Numbers
  1. if(S>score2) s=score2;
  2. if(S>score3) s=score3;
  3. if(s>score4) s=score4;
  4. if(s>score5) s=score5;
this is it.

Now to test it:

score1=10;
score2=15;
score3=8;
score4=12;
score5=9;

1) s=10;
2) s>15 no;
3) s>8 yes-> s=8;
4) s>12 no;
5) s>9 no;

6) s=8

As u can see it's 'alive' and working properly.

And why it would not work with LO and if-else?

It would not work becasue it's wrong logic to set number to random value,always instead set it to one of the scores and then search if there is a smaller number and secound that if-else chain would work only in loop.


Savage
Apr 23 '07 #18
remove all of "else"s and it is gonna work!
Apr 23 '07 #19
Glad to hear that!!

So here we go:

Start is the same:

int S=score1;

now to the important part:

Expand|Select|Wrap|Line Numbers
  1. if(S>score2) s=score2;
  2. if(S>score3) s=score3;
  3. if(s>score4) s=score4;
  4. if(s>score5) s=score5;
this is it.

Now to test it:

score1=10;
score2=15;
score3=8;
score4=12;
score5=9;

1) s=10;
2) s>15 no;
3) s>8 yes-> s=8;
4) s>12 no;
5) s>9 no;

6) s=8

As u can see it's 'alive' and working properly.

And why it would not work with LO and if-else?

It would not work becasue it's wrong logic to set number to random value,always instead set it to one of the scores and then search if there is a smaller number and secound that if-else chain would work only in loop.


Savage

OK, so how can I get it to return a value
Apr 23 '07 #20
ilikepython
844 Expert 512MB
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 Expert 1GB
Yup.

And then when u call the function call it like:

int s;//this is in main

s=findLowest(score1,score2,score3,score4,score5);

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

Savage
Apr 23 '07 #22
Yup.

And then when u call the function call it like:

int s;//this is in main

s=findLowest(score1,score2,score3,score4,score5);

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

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

Savage
Apr 23 '07 #24
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 Expert Mod 4TB
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
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 Expert 1GB
[quote=namcintosh]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 Expert 2GB
It looks like you are missing a semicolon after the declaration.
Apr 24 '07 #29
Savage
1,764 Expert 1GB
I can't belive that i writed semicolumn instead of semicolon.LOL

Savage
Apr 24 '07 #30
Alright, then, here is my program.

I've already ran the program, but I still want you to run int and see what you think of it.


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, int, int, int, int, int, int);
  9. int main()
  10. {
  11.         int average, score1, score2, score3, score4, score5, small;
  12.  
  13.         getscore (score1, score2, score3, score4, score5);
  14.         calcAverage (average, score1, score2, score3, score4, score5, small);
  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, int score1, int score2, int score3, int score4, int score5, int small)
  36. {
  37.  
  38.  
  39.         average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
  40.  
  41.         cout << average;
  42.  
  43. }
  44. int findLowest(int small, int score1, int score2, int score3, int score4, int score5)
  45. {
  46.         small =score1;
  47.  
  48.         if(small>score2)
  49.         {
  50.         small=score2;
  51.         }
  52.         if(small>score3)
  53.         {
  54.         small=score3;
  55.         }
  56.         if(small>score4)
  57.         {
  58.         small=score4;
  59.         }
  60.         if(small>score5)
  61.         {
  62.         small=score5;
  63.         }
  64.         return small; 
  65. }
Thanks for the encouragement, goys!!
Apr 24 '07 #31
Savage
1,764 Expert 1GB
Can't see any error.

It should work,probably :D

Savage
Apr 24 '07 #32
Can't see any error.

It should work,probably :D

Savage
Uh- oh, I think I ran into a problem:

When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???
Apr 24 '07 #33
Savage
1,764 Expert 1GB
Uh- oh, I think I ran into a problem:

When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???
In main set average to 0 before calling the function.
Apr 24 '07 #34
In main set average to 0 before calling the function.
I tried that, and this is what happened:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.         int average = 0, score1, score2, score3, score4, score5, small;
  4.  
  5.         getscore (score1, score2, score3, score4, score5);
  6.         calcAverage (average, score1, score2, score3, score4, score5, small);
  7.         getch();
  8.         return 0;
  9. }
  10. Enter first score: 100
  11. Enter second score: 100
  12. Enter third score: 100
  13. Enter fourth score: 100
  14. Enter fifth score: 100
  15. 125
It's still outputting 125.
Apr 24 '07 #35
Ganon11
3,652 Expert 2GB
Hint: When, in your program, are you finding small?
Apr 24 '07 #36
Hint: When, in your program, are you finding small?
I'm finding small in my findLowest() function
Apr 24 '07 #37
Savage
1,764 Expert 1GB
Uh- oh, I think I ran into a problem:

When I entered the values 100, 100, 100, 100, 100, it gave me an average of 125. Why did that happen???
U are missing caller for findLowest() inside main() so it's just seting it to 0:

average=(100+100+100+100+100)-0)/4=125;

This should fix that!!

Savage
Apr 24 '07 #38
U are missing caller for findLowest() inside main() so it's just seting it to 0:

average=(100+100+100+100+100)-0)/4=125;

This should fix that!!

Savage
I tried that, and the same thing happened.

Actually, here are the instructions:
void calcAverage()-should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.

int findLowest()-should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

So, what am I doing wrong??:-(
Apr 24 '07 #39
Savage
1,764 Expert 1GB
I tried that, and the same thing happened.

Actually, here are the instructions:
void calcAverage()-should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores.

int findLowest()-should find and return the lowest of the five scores passed to it. It should be called by the calcAverage, who uses the function to determine which of the five scores to drop.

So, what am I doing wrong??:-(
How did u added the caller was it like:

small=findLowest(score1,score2,score3,score4,score 5);


???

Savage
Apr 24 '07 #40
How did u added the caller was it like:

small=findLowest(score1,score2,score3,score4,score 5);


???

Savage
What do u mean, how did I add the caller
Apr 24 '07 #41
Savage
1,764 Expert 1GB
What do u mean, how did I add the caller

Sorry,I was asking u how have u called function inside main.Was it called the same way as in my previous post?


PS:I have need for sleep.(ZzzzzzzzzZzzzzzz)


Savage
Apr 24 '07 #42
Sorry,I was asking u how have u called function inside main.Was it called the same way as in my previous post?


Savage
Yes, it was, and I still ran crazy. Run my program, please and you will see what I mean.
Apr 24 '07 #43
Savage
1,764 Expert 1GB
Yes, it was, and I still ran crazy. Run my program, please and you will see what I mean.
i fixed it:

This is what I have changed:


int findLowest (int, int, int, int, int);//there was six of them small is unecsasary.

//main
int average=0, score1=0, score2=0, score3=0, score4=0, score5, small=0;

//getscore
small=findLowest(score1,score2,score3,score4,score 5);
//calcAverage
//gethc and return

and finaly ur function:

int small =score1;//we don't pass small to the function therefore we create another variable.

I have runed this and output is 100.

Savage
Apr 24 '07 #44
i fixed it:

This is what I have changed:


int findLowest (int, int, int, int, int);//there was six of them small is unecsasary.

//main
int average=0, score1=0, score2=0, score3=0, score4=0, score5, small=0;

//getscore
small=findLowest(score1,score2,score3,score4,score 5);
//calcAverage
//gethc and return

and finaly ur function:

int small =score1;//we don't pass small to the function therefore we create another variable.

I have runed this and output is 100.

Savage
I hate to sound like a complete martian, but can you please explain to me what each line means???
Apr 25 '07 #45
Savage
1,764 Expert 1GB
In my first line I have changed ur prototype dunction definition.It was like:

findLowest(int,int,int,int,int,int) to findLowest(int,int,int,int,int);
the sixth argument,small, is unecsessary and I thought it might represent a problem.

In my secound line I have set all the variables to 0 value because that's neutral value for addition.

In 3 line I added the call for findLowest.

small=findLowest(score1,score2,score3,score4,score 5);

and finaly in function, findLowest(), declaration I changed this:

int findLowest(int score1,int score2,int score3,int score4,int score5,int small)
to

int findLowest(int score1,int score2,int score3,int score4,int score5)

and then line after I chnaged this:small=score1;

to

int small=score1;


Savage
Apr 25 '07 #46
This is what I did:

Expand|Select|Wrap|Line Numbers
  1. void getscore(int&, int&, int&, int&, int&);
  2. int findLowest (int, int, int, int, int);
  3. void calcAverage (int, int, int, int, int, int, int);
  4. int main()
  5. {
  6.         int average=0, score1=0, score2=0, score3=0, score4=0, score5=0, small=0;
  7.  
  8.         getscore (score1, score2, score3, score4, score5);
  9.         calcAverage (average, score1, score2, score3, score4, score5, small);
  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, int score1, int score2, int score3, int score4, int score5, int small)
  31. {
  32.  
  33.  
  34.         average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
  35.  
  36.         cout << average;
  37.  
  38. }
  39. int findLowest(int score1, int score2, int score3, int score4, int score5)
  40. {
  41.         int 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. }
My output still came out to be 125. I don't know whether or not I put those things in the right place.
Apr 25 '07 #47
ilikepython
844 Expert 512MB
This is what I did:

Expand|Select|Wrap|Line Numbers
  1. void getscore(int&, int&, int&, int&, int&);
  2. int findLowest (int, int, int, int, int);
  3. void calcAverage (int, int, int, int, int, int, int);
  4. int main()
  5. {
  6.         int average=0, score1=0, score2=0, score3=0, score4=0, score5=0, small=0;
  7.  
  8.         getscore (score1, score2, score3, score4, score5);
  9.         calcAverage (average, score1, score2, score3, score4, score5, small);
  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, int score1, int score2, int score3, int score4, int score5, int small)
  31. {
  32.  
  33.  
  34.         average = ((score1 + score2 + score3 + score4 + score5)-small)/4;
  35.  
  36.         cout << average;
  37.  
  38. }
  39. int findLowest(int score1, int score2, int score3, int score4, int score5)
  40. {
  41.         int 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. }
My output still came out to be 125. I don't know whether or not I put those things in the right place.
You never called findLowest, so small is equal to 0. Call findLowest before you call calcavergae().
Apr 25 '07 #48
Savage
1,764 Expert 1GB
Have patiance:

Look at the caller order:

//getscore
small=findLowest(score1,score2,score3,score4,score 5);
//calcAverage

Have u seend this?

Also ilikepython sayed the same thing.

Read every post slowly word by word and ur problem will banish.

Savage
Apr 25 '07 #49
I am still having problems:-(

I am following you all's suggestions, and it's still coming out to be 125.
Apr 27 '07 #50

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

Similar topics

4
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...
4
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...
3
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...
6
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,...
2
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...
5
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...
1
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...
2
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...
3
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++....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.