HELP!!

closed account (3pk1T05o)
I am completely lost on what to do next, here's my code:<>


# include <iostream>
# include <string>
using namespace std;
//function prototyping
void getRaceTimes(string&, double&);
void findWinner(string, string, string, double, double, double);
void welcome();
double raceAverage(double, double, double);

int main()
{
string name1;
string name2;
string name3;
double time1;
double time2;
double time3;

cout << "*****************************************************************************\n";
cout << "Welcome to Race Results Program\n";
cout << "You are Asked to Enter the Three Racers Names and their Associated Race Time\n " << endl;


cout << "Please enter a real number for the Race Time (the race time must be > 0)\n";
cout << "Program Developed by: Samantha Cartossa\n";
cout << "******************************************************************************\n" << endl;
//declare variables racers & times & your average
//then call your function

cout << "Please enter racer ones name > \n ";
cin >> name1;
cout << "Enter racer ones time > \n";
cin >> time1;

cout << "Please enter racer twos name > \n ";
cin >> name2;
cout << "Enter racer twos time > \n";
cin >> time2;

cout << "Please enter racer threes name >\n";
cin >> name3;
cout << " Enter racer threes time > \n";
cin >> time3;

return 0;
}
//function definition
void getRaceTimes(string&racerName, double&racerTime)
{

}
void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{

}
void welcome()
{

}
double raceAverage(double, double, double)
{
return 0.0;
}
double raceAverage(double time1, double time2, double time3, double average)
{

//need to calculate average
return 0;
}

Last edited on
pls use code tags

<> on the right of where you type.
closed account (3pk1T05o)
What do you mean by that?
closed account (48T7M4Gy)
Who is Samantha Cartossa?
closed account (3pk1T05o)
That is me. I need a do while loop to finish and i cant figure out how to use it.
closed account (48T7M4Gy)
http://www.cplusplus.com/doc/tutorial/control/

This tutorial and samples might help.

When you've read that come back with a question about the problem you are trying to solve. So far you haven't done that.
closed account (3pk1T05o)
# include <iostream>
# include <string>
using namespace std;
//function prototyping
void getRaceTimes(string&, double&);
void findWinner(string, string, string, double, double, double);
void welcome();
double raceAverage(double, double, double);

int main()
{
void welcome();
void getRaceTimes();
void findWinner();
void raceAverage();

return 0;
}
//function definition
void getRaceTimes(string&racerName, double&racerTime)
{
string name1;
string name2;
string name3;
double time1;
double time2;
double time3;

cout << "Please enter racer ones name: \n ";
cin >> name1;
cout << "Enter racer ones time: \n";
cin >> time1;

cout << "Please enter racer twos name: \n ";
cin >> name2;
cout << "Enter racer twos time: \n";
cin >> time2;

cout << "Please enter racer threes name: \n";
cin >> name3;
cout << "Please enter racer threes time: \n";
cin >> time3;
}
void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{
while (time1&&time2&&time3 > 0)
{
void getRaceTimes();

if (time1 > time2&&time3)
{
cout << "Racer one is the winner!";
}
else if (time2 > time1&&time3)
{
cout << "Racer two is the winner!";
}
else if (time3 > time1&&time2)
{
cout << "Racer three is the winner!";
}
else if (time1 == time2 > time3)
{
cout << "Rancer 1 and 2 have tied";
}
else if (time1 == time3 > time2)
{
cout << "Racers 1 and 3 have tied!";
}
else if (time2 == time3 > time1)
{
cout << "Racers 2 and 3 have tied!";
}
break;
}
}
void welcome()
{
cout << "*****************************************************************************\n";
cout << "Welcome to Race Results Program\n";
cout << "You are Asked to Enter the Three Racers Names and their Associated Race Time\n " << endl;


cout << "Please enter a real number for the Race Time (the race time must be > 0)\n";
cout << "Program Developed by: Samantha Cartossa\n";
cout << "******************************************************************************\n" << endl;
}
double raceAverage(double, double, double)
{
double average = 0;
void getRaceTimes();
average = (double time1 + double time2 + double time3) / 3.0;
return average;
}
closed account (48T7M4Gy)
What's the problem?

I assume from this latest version you don't want to/don't know how to/aren't allowed to use arrays.

Arrays (two - one for name and one for times make the job a little easier.

Also knowledge and application of passing parameters by reference wouldn't go astray.

void welcome() for calling up the welcome function should be just welcome(). This same comment applies when you call the other functions in main.

To find the winner all you need to do is find the racer with the least time. There is no need for the extensive if's you have.
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# include <iostream>
# include <string>

using namespace std;

void welcome();
void getRaceTimes(string&, string&, string&, double&, double&, double&);
double raceAverage(double, double, double);
void findWinner(string &, double &, string, string, string, double, double, double);

int main()
{
    string name1, name2, name3;
    double time1 = 0, time2 = 0, time3 = 0;
    
    string winnerName;
    double winningTime = 0;
    
    welcome();
    
    getRaceTimes(name1, name2, name3, time1, time2, time3);
    double average = raceAverage(time1, time2, time3);
    cout << "Average: " << average << endl;
    
    findWinner(winnerName, winningTime, name1, name2, name3, time1, time2, time3);
    cout << " Winner: " << winnerName << endl;
    cout << "   Time: " << winningTime << endl;
    
    return 0;
}

void getRaceTimes(string &n1, string &n2, string &n3, double &t1, double &t2, double &t3)
{
    cout << "Please enter racer ones name: \n ";
    cin >> n1;
    cout << "Enter racer ones time: \n";
    cin >> t1;
    
    cout << "Please enter racer twos name: \n ";
    cin >> n2;
    cout << "Enter racer twos time: \n";
    cin >> t2;
    
    cout << "Please enter racer threes name: \n";
    cin >> n3;
    cout << "Please enter racer threes time: \n";
    cin >> t3;
    
    return;
}

void findWinner(string &wn, double &wt, string n1, string n2, string n3, double t1, double t2, double t3)
{
    wn = n1;
    wt = t1;
    
    if (t2 < wt)
    {
        wt = t2;
        wn = n2;
    }
    
    if (t3 < wt)
    {
        wt = t3;
        wn = n3;
    }
    
    return;
}

void welcome()
{
    cout << "*****************************************************************************\n";
    cout << "Welcome to Race Results Program\n";
    cout << "You are Asked to Enter the Three Racers Names and their Associated Race Time\n " << endl;
    
    
    cout << "Please enter a real number for the Race Time (the race time must be > 0)\n";
    cout << "Program Developed by: Samantha Cartossa\n";
    cout << "******************************************************************************\n" << endl;
    
    return;
}

double raceAverage( double t1, double t2, double t3)
{
    return (t1 + t2 + t3)/3;
}
@OP More people will read your code and help you out, if you make your post more readable. To do that, please use code tags:

http://www.cplusplus.com/articles/z13hAqkS/
closed account (3pk1T05o)
Now I can't figure out why the 3 way tie won't work <>

# include <iostream>
# include <string>
# include <cmath>
using namespace std;

//function prototyping
void getRaceTimes(string&, double&);
void findWinner(string, string, string, double, double, double);
void welcome();
double raceAverage(double, double, double);

int main()
{
string name1, name2, name3;
double time1 = 0;
double time2 = 0;
double time3 = 0;

welcome();
getRaceTimes(name1, time1); // Racer1
getRaceTimes(name2, time2); // Racer2
getRaceTimes(name3, time3); // Racer3
findWinner(name1, name2, name3, time1, time2, time3);
double average = raceAverage(time1, time2, time3);
cout << endl;
cout << endl;
cout << "Overall Race Time Average: " << average << endl;

return 0;
}
//function definition
void getRaceTimes(string&racerName, double&racerTime)
{
cout << "\nPlease enter racer's first name > ";
cin >> racerName;
cout << "\nPlease enter racer's time > ";
cin >> racerTime;
while (racerTime <= 0)
{
cout << "Invalid time input...time must be > 0" << endl;
cout << "Enter the racers time: ";
cin >> racerTime;
}


}
void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{
string winner;
double winningtime = 0;

while (time1&&time2&&time3 > 0)
{


if ((time1 == time2) && (time1 == time2) < time3)
{
winningtime = time1;
cout << "We have a TIE " << racer1 << " and " << racer2 << " win!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if ((time1 == time3) && (time1 == time3) < time2)
{
winningtime = time1;
cout << "We have a TIE " << racer1 << " and " << racer3 << " win!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if ((time2 == time3) && (time2 == time3) < time1)
{
winningtime = time2;
cout << "We have a TIE " << racer2 << " and " << racer3 << " win!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if (time1 < time2&&time3)
{
winner = racer1;
winningtime = time1;
cout << "Congratulations " << winner << "!!!" << "You are the winner!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if (time2 < time1&&time3)
{
winner = racer2;
winningtime = time2;
cout << "Congratulations " << winner << "!!!" << "You are the winner!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if (time3 < time1&&time2)
{
winner = racer3;
winningtime = time3;
cout << "Congratulations " << winner << "!!!" << "You are the winner!!" << endl;
cout << "***** Your winning time is: " << winningtime << " *****" << endl;
}
else if ((time1 == time2) && (time1 == time2) && (time2 == time3) && (time2 == time3) && (time1 == time3) && (time1==time3))
{
cout << "We have a 3 way TIE!! No winner for this race..." << endl;
}
break;
}

}
void welcome()
{
cout << "*****************************************************************************\n";
cout << "Welcome to Race Results Program\n";
cout << "You are Asked to Enter the Three Racers Names and their Associated Race Time\n " << endl;


cout << "Please enter a real number for the Race Time (the race time must be > 0)\n";
cout << "Program Developed by: Samantha Cartossa\n";
cout << "******************************************************************************\n" << endl;
}
double raceAverage(double time1, double time2, double time3)
{
double average = 0.0;
average = (time1 + time2 + time3) / 3.0;
return average;
}
Your conditions are messed up:

Line 51:
while (time1&&time2&&time3 > 0)
I don't think this line is doing what you expect.
It evaluates as:
while ((time1 != 0) && (time2 != 0) && (time3 > 0))

Line 55,61,67,73,80,87: Nor is this line doing what you want:
if ((time1 == time2) && (time1 == time2) < time3)
This evaluates to
if ( (bool && bool) < time3)

Line 94: Why do you have conditions repeated in this line?
else if ((time1 == time2) && (time1 == time2) && (time2 == time3) && (time2 == time3) && (time1 == time3) && (time1==time3))

TO answer you question, line 94 is an else if. That means if any of the previous (messed up) if statements are true, line 94 will never get evaluated.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.

Topic archived. No new replies allowed.