473,386 Members | 1,721 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,386 software developers and data experts.

How to calculate highest and lowest score using a while loop

16
the in input file is like
2 80 97
5 69 79 89 99 58
7 60 70 80 90 100 0 59
[
Oct 10 '10 #1

✓ answered by Geocool

Expand|Select|Wrap|Line Numbers
  1. if ( score > highscore )
  2.     highscore = score;
  3. else if (score < lowscore )
  4.     lowscore = score;
Add the above code after "cin >> score;"

You have declared lowerscore as 1 so if you enter 20 is bigger than your already given(1) lower score so it doesn't take it.

I suggest to set first input as lowscore.
like:

Expand|Select|Wrap|Line Numbers
  1. bool isfirstinput(true);
  2. while(!cin.eof()){
  3. ....
  4. ...
  5. cin >> score;
  6. if(isfirstinput==true)
  7. {
  8. lowscore=score;
  9. isfirstinput = false; // so it won't pass to lowscore again
  10. }
  11. ...
I hope this helps... ;)

3 5407
weaknessforcats
9,208 Expert Mod 8TB
I don't see you referencing highscore or lowscore inside your while loop.
Oct 11 '10 #2
Expand|Select|Wrap|Line Numbers
  1. if ( score > highscore )
  2.     highscore = score;
  3. else if (score < lowscore )
  4.     lowscore = score;
Add the above code after "cin >> score;"

You have declared lowerscore as 1 so if you enter 20 is bigger than your already given(1) lower score so it doesn't take it.

I suggest to set first input as lowscore.
like:

Expand|Select|Wrap|Line Numbers
  1. bool isfirstinput(true);
  2. while(!cin.eof()){
  3. ....
  4. ...
  5. cin >> score;
  6. if(isfirstinput==true)
  7. {
  8. lowscore=score;
  9. isfirstinput = false; // so it won't pass to lowscore again
  10. }
  11. ...
I hope this helps... ;)
Oct 11 '10 #3
nuken
16
I set lowscore equal to 100 and it works for the first one:
Oct 11 '10 #4

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

Similar topics

3
by: monomaniac21 | last post by:
hi all im querying a db for two rows which are always returned. how can i reference each row and output its contents without using a while loop. ive tried: $row = mysql_fetch_array($result);...
3
by: coolindienc | last post by:
If I want to use while loop instead for loop in below program, how would I do that? Andy import random heads = 0 for i in range(100): heads+=random.randrange(2)
6
by: apking | last post by:
please write the programe in c language for this Accept 5 Employee details to find highest salary employe name using for loop and arrays Thanks in advance
54
namcintosh
by: namcintosh | last post by:
First of all, here is my program: #include <iostream> #include <conio> using namespace std; //Function prototype void getscore(int&, int&, int&, int&, int&); void findLowest (int, int,...
2
by: jesmi | last post by:
when i put while loop, it never stops, it just trap in loop.but when i remove while loop, it will increment one by one, the month,year,week,day. but i need to put this code in while loop. please help...
13
by: inexploration | last post by:
Hello Sirs/madam i have 5 picture store in mysql , and now i want to display these picture on the page ,using while loop ., in php. please let me know through very very simple code. thanking you....
15
Markus
by: Markus | last post by:
What i want to do: Get urls from the database and echo them out into a multiple columned table i.e. 4 pictures per row (recently uploaded table) MY problem is: I have, in my MySQL database,...
2
by: nirav11 | last post by:
# include <iostream> # include <fstream> # include <iomanip> # include <cstdlib> // needed for exit () using namespace std; int main() { ifstream inFile; ofstream outFile;
2
by: Peter9588 | last post by:
I am trying to read in every line from a given file and check (amongst other things) that the 3rd character of every line is a ';' (a semi colon). The files i make to go into my database needs to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...

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.