Going blank after input

Currently my program will close after I input my racer's names and time.I was wondering if anyone could tell what I am doing wrong and give me some tips. There are a couple rules I have to follow for this program like no No Arrays or Vectors


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

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

int main()
{
double time1, time2, time3;
string racer1, racer2, racer3;

welcome();
getRaceTimes(racer1, time1);
getRaceTimes(racer2, time2);
getRaceTimes(racer3, time3);
findWinner( racer1, racer2, racer3, time1, time2, time3);
double result = raceAverage(time1, time2, time3);
cout << endl;
cout << "The overall average race time is" << " " << result;
return 0;
system("pause");
}

void getRaceTimes(string &racername, double &racertime)
{
cout << "Please enter racer's name" << endl;
cin >> racername;
do
{
cout <<"Please enter racer's time" << endl;
cin >> racertime;
if (racertime <= 0)
cout << "Im sorry that is an invalid time. Please re-enter a value greater than 0" << endl;
} while (racertime <= 0);


}

void findWinner(string racer1, string racer2, string racer3, double time1, double time2, double time3)
{
if ((time1 < time2) && (time1 < time3))
{
cout << "Congratulations " << racer1 << " is the winner!" << endl;
cout << "Your winning time is" << time1 << endl;
}
else if ((time2 < time3) && (time2 < time1))
{
cout << "Congratulations " << racer2 << " is the winner!" << endl;
cout << "Your winning time is" << time2 << endl;
}
else if ((time3 < time1) && (time3 < time2))
{
cout << "Congratulations " << racer3 << " is the winner!" << endl;
cout << "Your winning time is" << time3 << endl;
}
else if ((time1 == time2) && (time1, time2 < time3))
{
cout << " We have a tie " << racer1 << " and " << racer2 << " win!" << endl;
cout << "Your winning time is" << time1 << endl;
}
else if ((time1 == time3) && (time1, time3 < time2))
{
cout << " We have a tie " << racer1 << " and " << racer3 << " win!" << endl;
cout << "Your winning time is" << time1 << endl;
}
else if ((time2 == time3) && (time2, time3 < time1))
{
cout << " We have a tie " << racer2 << " and " << racer3 << " win!" << endl;
cout << "Your winning time is" << time2 << endl;
}
else ((time1 == time2) && (time1 == time3));
{
cout << "We have a 3 way tie!! No winner for this race." << endl;

cout << "Your winning time is" << time1 << endl;


}
return;

}

void welcome()
{
cout << "*****************************************************************" << endl;
cout << " Welcome to race results program" << endl;
cout << " you are asked to enter the three racer’s names" << endl;
cout << " and their associated race time." << endl;
cout << " Please enter a real number for Race Time (the Race Time Must be > 0). " << endl;
cout << " Program Developed by : " << endl;
cout << "*****************************************************************" << endl;

}

double raceAverage(double time1, double time2, double time3)
{
double average = (time1 + time2 + time3) / 3;
return average;
}
does it work if you add this to the end of main (right at the return statement)
int stopper;
cin >> stopper;

if so, open a console and run the program from there, or do the above, or read the massive thread at the top of the beginners forum. If you don't know how to open a console and get to your program, you should learn at least a handful of dos and unix commands both, they will serve you well, do you need to see this?
Last edited on
@jonnin, actually in OP's main() there’s system("pause");, but it’s after return 0; :)

- - -

alexandrap98 wrote:
I was wondering if anyone could tell what I am doing wrong

Yes: your compiler can, and as a matter of fact it’s trying as hard as it can:

compiler wrote:
In function 'void findWinner(std::string, std::string, std::string, double, double, double)':
60:46: warning: left operand of comma operator has no effect [-Wunused-value]
65:46: warning: left operand of comma operator has no effect [-Wunused-value]
70:46: warning: left operand of comma operator has no effect [-Wunused-value]

It means comma operator is of no avail
here: else if ((time1 == time2) && (time1, time2 < time3))
and here: else if ((time1 == time3) && (time1, time3 < time2))
and here: else if ((time2 == time3) && (time2, time3 < time1))

About comma operator:
http://www.cplusplus.com/doc/tutorial/operators/ (after half page)

alexandrap98 wrote:
and give me some tips

Tip: if time1 == time2, do you really need to compare both of them to time3?

Other tips:
a) use code tags or you could get no answers (you wouldn’t be the first):
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

b) You can consider posting simple codes in the Beginners section of this forum.

c) Read this for how to improve your chances to get a good answer:
http://www.cplusplus.com/forum/beginner/1/
Oh, yes, there’s another issue:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void findWinner(std::string racer1, std::string racer2, std::string racer3,
                double time1, double time2, double time3)
{
    ...

    else ((time1 == time2) && (time1 == time3));
    {
        cout << "We have a 3 way tie!! No winner for this race." << endl;
        
        cout << "Your winning time is" << time1 << endl;
    
    
    }
    return;
}

“else” cannot ‘manage’ a condition: you need an “if” for that:
else if ((time1 == time2) && (time1 == time3))
without any semicolon at the end.
or, in beginner speak,
conditions are explicit. the compiler does not get human like if a,b,c < d. It only gets a < d && b<d && c<d spelled out.
else if is not a thing in c++ but many people put them together to chain. Its really 2 distinct if block /statements, no matter how it looks in the code, and the second if is inside the else part of the first if. So they are nested, but distinct.

simplifying a bunch of related if statements takes practice. For now, do them explicitly. Later you can work on your boolean math skills to trim the fat.
Topic archived. No new replies allowed.