[Show all top banners]

prankster
Replies to this thread:

More by prankster
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 Assistance with debugging C++ Program
[VIEWED 6878 TIMES]
SAVE! for ease of future access.
Posted on 10-27-14 10:40 AM     [Snapshot: 40]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

Tested following modified code in http://www.compileonline.com/compile_cpp_online.php

#include
#include
#include
using namespace std;

/* This program computes the score for a dive based on the degree of difficulty
* and five judges scores. The high and low scores are dropped.
*/

/* Function prototypes */
void inputScores(double scores[]);
double addAllScores(double scores[]);
double findLowScore(double scores[]);
double findHighScore(double scores[]);

int main ()
{
double difficulty, sum, lowScore, highScore, score;
double judgeScores[5];

cout << "Please enter the degree of difficulty: ";
cin >> difficulty;

inputScores(judgeScores);

sum = addAllScores(judgeScores);

lowScore = findLowScore(judgeScores);

highScore = findHighScore(judgeScores);

/* subtract out the low and high scores */
sum = sum - lowScore - highScore;

/* multiply by degree of difficulty */
score = sum * difficulty;

cout << "The score for the dive is: " << fixed << setprecision(2) << score << endl;
//system("pause");
}

//****************************************************************
// This function gets the judges scores
//***************************************************************

void inputScores(double scores[])
{
for(int i = 1; i < 5; i++)
{
scores[i] = i;
//cout << "Please enter the score from Judge #" << i + 1 << ": ";
//cin >> scores[i];
}
}

//****************************************************************
//This function determines the sum of the scores input.
//****************************************************************

double addAllScores(double scores[])
{
double total;

//determine lowest score
for (int count = 0; count < 5; count++)
{
total += scores[count];
}
return total;
}

//****************************************************************
//This function determines the lowest score input.
//****************************************************************

double findLowScore(double scores[])
{
double lowest = 99999.0;

//determine lowest score
for (int count = 0; count <= 5; count++)
{
if (lowest > scores[count])
lowest = scores[count];
}
return lowest;
}

//****************************************************************
//This function determines the highest score input.
//****************************************************************

double findHighScore(double scores[])
{
double highest = -1;

//determine lowest score.
for (int count = 0; count < 5; count++)
{
if (highest < scores[count])
highest = scores[count];
}
return highest;
}


Inputs and rest of the debug
Difficulty = 6
Scores[0] = 0
scores[1] = 1
.
.
scores[4] = 4

highest = 4,
lowest = 0,
total = 1+2+3+4 = 10
sum = total - highest - lowest = 10 - 4 - 0 = 6
score =sum * difficult = 6 * 6 = 36
 
Posted on 10-27-14 11:01 AM     [Snapshot: 63]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

not sure about the error, I don't think it is related to your code, may be you have configured VS wrong.
Change inputScores to,
void inputScores(double scores[])
{
for(int i = 0; i < 5; i++)
{
cout << "Please enter the score from Judge #" << i + 1 << ": ";
cin >> scores[i];
}
}

for inputs.
 
Posted on 10-27-14 3:26 PM     [Snapshot: 180]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

initialize it to 0 ?
 
Posted on 10-27-14 4:22 PM     [Snapshot: 218]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

change
count<=5 to count<5 in determine lowest score

Will you code work if all the values are above 99999.0 or all the values are less than -1?
If you want them to work with all the values , assign first score to highest/lowest :)
 
Debbie Barnard Smith.
Posted on 02-28-16 2:22 PM     [Snapshot: 1077]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

How did you get it to equal 42.55. I am working on this same program trying to debug it and can't get it to equal 42.55.
 
Posted on 02-28-16 11:42 PM     [Snapshot: 1209]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

wondering why you using
for(int i = 1; i < 5; i++) and
for(int i = 0; i < 5; i++) and
for(int i = 0; i <= 5; i++) ....they all should same ideally 0 to < 5 if size is 5
instead of hard code 5, just use scores.size(),,,,,,done

 
Debbie Barnard Smith.
Posted on 02-29-16 12:26 PM     [Snapshot: 1300]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

Here is my program. It should equal 42.55. It's not dropping the lowest score.

#include
#include
#include
using namespace std;

/* This program computes the score for a dive based on the degree of difficulty
* and five judges scores. The high and low scores are dropped.
*/

/* Function prototypes */
void inputScores(double scores[]);
double addAllScores(double scores[]);
double findLowScore(double scores[]);
double findHighScore(double scores[]);

int main()
{
double difficulty, sum, lowScore, highScore, score;
double judgeScores[5];

cout << "Please enter the degree of difficulty: ";
cin >> difficulty;

inputScores(judgeScores);

sum = addAllScores(judgeScores);

lowScore = findLowScore(judgeScores);

highScore = findHighScore(judgeScores);

/* subtract out the low and high scores */
sum = sum - lowScore - highScore;

/* multiply by degree of difficulty */
score = sum * difficulty;

cout << "The score for the dive is: " << fixed << setprecision(2) << score << endl;
system("pause");
}

//****************************************************************
// This function gets the judges scores
//***************************************************************

void inputScores(double scores[])
{
for (int i = 0; i < 5; i++)
{
cout << "Please enter the score from Judge #" << i + 1 << ": ";
cin >> scores[i];
}
}

//****************************************************************
//This function determines the sum of the scores input.
//****************************************************************

double addAllScores(double scores[])
{
double total = 0;

//determine sum of score
for (int count = 0; count < 5; count++)
{
total += scores[count];
}
return total;
}

//****************************************************************
//This function determines the lowest score input.
//****************************************************************

double findLowScore(double scores[])
{
double lowest = 0;

//determine lowest score
for (int count = 0; count < 5; count++)
{
if (lowest < scores[count])
lowest = scores[count];
}
return lowest;
}

//****************************************************************
//This function determines the highest score input.
//****************************************************************

double findHighScore(double scores[])
{
double highest = 0;

//determine highest score.
for (int count = 0; count < 5; count++)
{
if (highest > scores[count])
highest = scores[count];
}
return highest;
}
 
Posted on 02-29-16 6:51 PM     [Snapshot: 1359]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

void inputScores(double scores[]) should return double[] values......array is not passed by reference ..so change function as:
double[] inputScores(double scores[])
{
for (int i = 0; i < 5; i++)
{
cout << "Please enter the score from Judge #" << i + 1 << ": ";
cin >> scores[i];
}
return scores;
}

and judgeScores = inputScores(judgeScores); .and call other methods....will work
 
Debbie Barnard Smith.
Posted on 03-18-16 2:48 PM     [Snapshot: 1529]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

It is still not working.
 
Posted on 03-25-16 2:52 PM     [Snapshot: 1710]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

Debbie did you ever get this to work

 
Debbie Barnard Smith.
Posted on 03-25-16 2:55 PM     [Snapshot: 1712]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

I think so. I changed this part:
double findHighScore(double scores[])
{
double highest = 0;

to:

double findHighScore(double scores[])
{
double highest = 99999.0;
 
Posted on 03-25-16 3:03 PM     [Snapshot: 1725]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

Still unable to get it to work.. can you attach your whole program to compare to what I have
 
Debbie Barnard Smith.
Posted on 03-25-16 3:07 PM     [Snapshot: 1731]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

This is what I have, let me know if it worked for you.

#include
#include
#include
using namespace std;

/* This program computes the score for a dive based on the degree of difficulty
* and five judges scores. The high and low scores are dropped.
*/

/* Function prototypes */
void inputScores(double scores[]);
double addAllScores(double scores[]);
double findLowScore(double scores[]);
double findHighScore(double scores[]);

int main()
{
double difficulty, sum, lowScore, highScore, score;
double judgeScores[5];

cout << "Please enter the degree of difficulty: ";
cin >> difficulty;

inputScores(judgeScores);

sum = addAllScores(judgeScores);

lowScore = findLowScore(judgeScores);

highScore = findHighScore(judgeScores);



/* subtract out the low and high scores */
sum = sum - lowScore - highScore;

/* multiply by degree of difficulty */
score = sum * difficulty;

cout << "The score for the dive is: " << fixed << setprecision(2) << score << endl;
system("pause");
}

//****************************************************************
// This function gets the judges scores
//***************************************************************

void inputScores(double scores[])
{

for (int i = 0; i < 5; i++)
{
cout << "Please enter the score from Judge #" << i + 1 << ": ";
cin >> scores[i];
}

}


//****************************************************************
//This function determines the sum of the scores input.
//****************************************************************

double addAllScores(double scores[])
{
double total = 0;

//determine sum of score
for (int count = 0; count < 5; count++)
{
total += scores[count];
}
return total;
}

//****************************************************************
//This function determines the lowest score input.
//****************************************************************

double findLowScore(double scores[])
{
double lowest = 0;

//determine lowest score
for (int count = 0; count < 5; count++)
{
if (lowest < scores[count])
lowest = scores[count];
}
return lowest;
}

//****************************************************************
//This function determines the highest score input.
//****************************************************************

double findHighScore(double scores[])
{
double highest = 99999.0;

//determine highest score.
for (int count = 0; count < 5; count++)
{
if (highest > scores[count])
highest = scores[count];
}
return highest;
}
 
Posted on 03-25-16 3:21 PM     [Snapshot: 1743]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

You are a lifesaver thank you so much..can we share emails in case I need some more help lol
 
Debbie Barnard Smith.
Posted on 03-25-16 3:47 PM     [Snapshot: 1769]     Reply [Subscribe]
Login in to Rate this Post:     0       ?        
 

I'm sending you a message with my email on Facebook. I found your page.
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
TRUMP 2016!!! Here is why?
How long does it take to get I485 approved?
कोमल ओलि र धिरेन्द्र बिचको अफेयर
Anyone renewed their passport through DC embassy lately?
Wedding Costs in Nepal ? Party, Band Baaja !!!!???
~चौतारी १९९~
Returning to Nepal
TPS FEDERAL NOTICE
Don't apply Canada Immigration through COLIN R. SINGER
Udus killer spray
हामीहरुले २० जना केटिहरुसंग सेक्स गर्नै पर्छ रे नी !
TPS to GC (PERM-I140-I485) TimeLine
लिङ्ग को आकर कत्रो?
नफर्किने गरि नेपाल जाने सोच
वाह ! मन्त्री ज्यु वाह !
रवि लामिछानेले येसोरी हत्या गर्यो शालिकराम पुडासैनीको ( with video )
Desi consultancy issue. Not to Compete of your employment agreement violations
Paras Shah and Sonika Singh with Huge Money !
❤ नारी दर्पण ❤
How much saving you have?
Don't apply Canada Immigration through COLIN R. SINGER
Funny jokes
Former U.S. President Bill Clinton in Nepal
~चौतारी १९९~
TRUMP 2016!!! Here is why?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters