Personal Best

So I wrote this today, but it closes upon first input.

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
90
91
92
93
94
95
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    string name;
    double hyt1, hyt2, hyt3, d1, d2, d3, m1, m2, m3, y1, y2, y3;//hyt=height, d1-3=day, m1-3=month, y1-3 = year
    cout << " Enter the name of the pole vaulter: ";
    cin >> name;
    cout << " Enter one the vaulter's best height in feet: ";
    cin >> hyt1;
    cout << " Enter the day, month, and year it was achieved. (Seperate with sapces) ";
    cin >> d1 >> m1 >> y1;
    cout << " Enter a second height for the vaulter: ";
    cin >> hyt2;
    cout << " Enter the day, month, and year it was achieved. (Seperate with sapces) ";
    cin >> d2 >> m2 >> y2;
    cout << " Enter a third height for the vaulter: ";
    cin >> hyt3;
    cout << " Enter the day, month, and year it was achieved. (Seperate with sapces) ";
    cin >> d3 >> m3 >> y3;
{  
    if (hyt1 < 2 && hyt1 > 5 || hyt2 < 2 && hyt2 > 5 || hyt3 < 2 && hyt3 > 5)
{
{    //check if height 1 was highest
if(hyt1 > hyt2 && hyt1 > hyt3)
  {
    if(hyt2 > hyt3) //if he did, then check to see where 2 and 3 placed
     {
        cout << " " << name << "'s best times are as follows: \n";
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
     }
    else
     {
        cout << " " << name << "'s best times are as follows: \n";
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;
     }   
  }
}
{    //check if height 2 was highest
if(hyt2 > hyt1 && hyt2 > hyt3)
  {
    if(hyt1 > hyt3) //if he did, then check to see where 1 and 3 placed
     {
        cout << " " << name << "'s best times are as follows: \n";
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
     }
    else
     {
        cout << " " << name << "'s best times are as follows: \n";
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
     }                   
  }
}
{ // check to see if 3rd was the highest
if(hyt3 > hyt1 && hyt3 > hyt2)
  {
    if(hyt1 > hyt2) //if it is, then check to see where 1 and 3 placed
     {
        cout << " " << name << "'s best times are as follows: \n";
        
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;    
        
     }
    else
     {
        cout << " " << name << "'s best times are as follows: \n";
        cout << hyt3 <<('\t') << ('\t') << d3<<"/"<<m3<<"/"<<y1<<endl;
        cout << hyt2 <<('\t') << ('\t') << d2<<"/"<<m2<<"/"<<y2<<endl;
        cout << hyt1 <<('\t') << ('\t') << d1<<"/"<<m1<<"/"<<y1<<endl;
     }                          
  }
}

else
    {
     cout << " That height is invalid.";
     }
}
}
    system("PAUSE");
    return EXIT_SUCCESS;
}


help me figure it out please :D
I'm totally new to programming... only started last month so I am a total noob xD
___________
updated the code to the one i have now
Last edited on
Do you really want to store the vaulter's name in a float?
You want to make name a string. Entering alphas (a name) into a float is invalid input.
i had it in string first, but i got a whole bunch of errors, so to see what i could do to fix it, i changed it to float, and the errors went away o.o
i'll change it back to see what happens.
_________________________________________________

ok so i changed to string, then i could move to the next inputs.
i can now input all the info, BUT, the parameters i was trying to set, did not work ( to try to keep the inputs between 2 and 5) AND, after the last input, the the program closed by itself.

i entered '1' for one of the heights, do you think it let me input everything, but because one of the heights where not in the required range, it closed the program?
Last edited on
Check the pairing of your open and close braces with your if/else statements.
You probably want the else at line 86 to be paired with the if at line 24.
It appears to me to be paired with the if at line 65.

You have some extra open/close brace pairs. That's harmless, but confusing.
all of em matched up i think except for line 64& 84. i added a close to line 84
line 95 close is suppose to go with line 25 open
and yea i want the else at 86 to go with the if at 24

_________________

compliler telling me the folowing, with the code as i have it now.

D:\Dev C++\Personal Best.cpp In function `int main()':
88 D:\Dev C++\Personal Best.cpp expected primary-expression before "else"
88 D:\Dev C++\Personal Best.cpp expected `;' before "else"
Last edited on
bump o.o still need help D:
i added a close to line 84


Which means the else on line 87 is paired up with no if. It looks like you had maybe an extra brace in a spot or two, and instead of getting rid of them, you added others in arbitrary places.

Proper indentation would go a long way towards seeing what's wrong.

i want the else on line 87 to be paired with the very first if statement on line 25.
sorry for the bad punctuation
Topic archived. No new replies allowed.