Please help

Hello forum. I am new to programming, I understand most of the concepts but sometimes get stuck at some easy problems.
Here I need to ask user to manually type in the id number of the team, enter win lose and draw data. It then calculates total games value and checks if its less or equal to 16. Then my program should calculate the winning average which is wins/games and output the averages as 0.9876 ( 4 decimals ) form. It just outputs it as a 0 and not the desired form. I tired using it as float, long and double but it is always gives me the same result. Please help. Thanks.
//

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int wins, losses, draws;
int remaining, games;
float w_average;
int team [10];

for (int n_teams=1; n_teams<=10; n_teams++)

{

cout << "Enter the team number: ";
cin >> team[n_teams];
cout << "Enter the number of Wins: ";
cin >> wins;
cout << "Enter the number of Losses: ";
cin >> losses;
cout << "Enter the number of Draws: ";
cin >> draws;

games = wins + losses + draws;
remaining = 16-games;
w_average = wins/games;


cout << "The number of Wins: " << wins << endl;
cout << "The number of Losses: " << losses << endl;
cout << "The number of Draws: " << draws << endl;
cout << "The number of Games: " << games << endl;
cout << setprecision (5) << "The winning average is: " << w_average << endl;


if (remaining ==0)
cout << "Season is Finished!" << endl;

else if (remaining <0)
{
cout << "Enter Valid Data!" << endl;
cout << "Enter the number of Wins: ";
cin >> wins;
cout << "Enter the number of Losses: ";
cin >> losses;
cout << "Enter the number of Draws: ";
cin >> draws;
cout << "The number of Wins: " << wins << endl;
cout << "The number of Losses: " << losses << endl;
cout << "The number of Draws: " << draws << endl;
}
else
cout << "The number of Games Remaining: " << remaining << endl;

}
cout << "Thanks you!"<< endl;


return 0;
}
Change w_average = wins/games;

To: w_average = double(wins) / games ;

To understand why the int needs to be first converted to a double before the division, see: http://www.drpaulcarter.com/cs/common-c-errors.php#2.5
Thanks for quick reply...
it works for most of the time unless there are numbers like 0.2500 then the program sets the value as 0.25 not the 4 decimals

here its the input and output:

Enter the team number: 1234
Enter the number of Wins: 4
Enter the number of Losses: 7
Enter the number of Draws: 5
The number of Wins: 4
The number of Losses: 7
The number of Draws: 5
The number of Games: 16
The winning average is: 0.25
Season is Finished!

how can i fix it to the 4 decimals thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <iomanip>

int main()
{
    double w_average = 0.25 ;

    std::cout << w_average << '\n' ; // 0.25

    //  fixed-point notation, with four digits after the decimal point
    std::cout << std::fixed << std::setprecision(4) << w_average << '\n' ; // 0.2500

}
THANK YOU

here is my final code

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
int wins, losses, draws, teamID,remaining, games, n_teams, final_score;
double w_average;
int team [10];

for (n_teams=1; n_teams<=10; n_teams++) //for loop to stop when total number of teams reaches 8

{

cout << "Enter the team number: "; // let user enter the appropriate values for:
cin >> team[n_teams];
cout << "Enter the number of Wins: ";
cin >> wins; // wins
cout << "Enter the number of Losses: ";
cin >> losses; // losses
cout << "Enter the number of Draws: ";
cin >> draws; // draws
cout << "\n" << endl;

teamID = team[n_teams];
games = wins + losses + draws;
remaining = 16-games;
w_average = double (wins)/games;
final_score = (2*wins)+draws-losses;

if (remaining <0)

{
cout << "Enter Valid Data!" << endl;
cout << "Enter the number of Wins: ";
cin >> wins;
cout << "Enter the number of Losses: ";
cin >> losses;
cout << "Enter the number of Draws: ";
cin >> draws;
cout << "The Team ID: " << teamID << endl;
cout << wins << " Wins " << losses << " Losses " << draws << " ties " << endl;
cout << "The final team score is: " << final_score << endl;
}


cout << "The Team ID: " << teamID << endl;
cout << wins << " Wins " << losses << " Losses " << draws << " ties " << endl;
cout << "The number of Games played : " << games << endl;

if (remaining ==0)
cout << "Season is Finished!" << endl;
else if (remaining !=0)
cout << "The number of Games Remaining: " << remaining << endl;
else cout << endl;

cout << fixed << setprecision (4) << "The winning average is: " << w_average << endl;



if (draws > wins) //if statements for draws versus wins
cout << "The number of games tied is greater than the number of games won" << endl;
else if (draws == wins)
cout << "The number of games tied is equal to the number of games won" << endl;
else if (draws < wins)
cout << "The number of games tied is not greater than the number of games won" << endl;

if (losses > wins) //if statements for losses versus wins
cout << "The number of games tied is greater than the number of games lost"<< endl;
else if (losses == wins)
cout << "The number of games lost is equal to the number of games won" << endl;
else if (losses < wins)
cout << "The number of games tied is not greater than the number of games lost" << endl;

cout << "The final team score is: " << final_score << "\n" << endl; //calculate the finals team score

}
cout << "Thanks you!"<< endl;


return 0;
}

now the bold section is where i am having problems now...
if i set the values of wins, losses and draws to be more then 16 in sum, the program should say that the data incorrect enter new data and calculate until the sum is 16, but for some reason it does it once and skips to the end.
would you be able to point out what needs to be done. maybe a while loop
THANKS>
> if i set the values of wins, losses and draws to be more then 16 in sum,
> the program should say that the data incorrect enter new data and calculate until the sum is 16,
> but for some reason it does it once and skips to the end.

You can't do something repeatedly with an if statement; an if statement will execute at most once. You need a looping construct of some kind do something repeatedly.

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // *** postpone defining variables till just before their first use

    //int wins, losses, draws, teamID,remaining, games, n_teams, final_score;
    // double w_average;

    // int team [10]; // you don't need this array, do you?

    // *** with the array, this was wrong; array subscrpts go from zero to (N-1)
    // for (n_teams=1; n_teams<=10; n_teams++)

    for( int n_teams=0; n_teams<10 ; ++n_teams )
    {
        int teamID, wins, losses, draws ;
        cout << "Enter the team number: "; // let user enter the appropriate values for:
        //cin >> team[n_teams];
        cin >> teamID ;
        cout << "Enter the number of Wins: ";
        cin >> wins; // wins
        cout << "Enter the number of Losses: ";
        cin >> losses; // losses
        cout << "Enter the number of Draws: ";
        cin >> draws; // draws
        cout << "\n" << endl;

        int games = wins + losses + draws ;
        int remaining = 16-games;

        while( remaining < 0 )
        {
            cout << "Enter Valid Data!" << endl;
            cout << "Enter the number of Wins: ";
            cin >> wins;
            cout << "Enter the number of Losses: ";
            cin >> losses;
            cout << "Enter the number of Draws: ";
            cin >> draws;
            games = wins + losses + draws ;
            remaining = 16-games;
        }

        // *** move these here, compute after all the input is over
        double w_average = double (wins)/games;
        int final_score = (2*wins)+draws-losses;


        cout << "The Team ID: " << teamID << endl;
        cout << wins << " Wins " << losses << " Losses " << draws << " ties " << endl;
        cout << "The number of Games played : " << games << endl;

        if (remaining ==0)
            cout << "Season is Finished!" << endl;
        else if (remaining !=0)
            cout << "The number of Games Remaining: " << remaining << endl;
        else cout << endl;

        cout << fixed << setprecision (4) << "The winning average is: " << w_average << endl;



        if (draws > wins) //if statements for draws versus wins
            cout << "The number of games tied is greater than the number of games won" << endl;
        else if (draws == wins)
            cout << "The number of games tied is equal to the number of games won" << endl;
        else if (draws < wins)
            cout << "The number of games tied is not greater than the number of games won" << endl;

        if (losses > wins) //if statements for losses versus wins
            cout << "The number of games tied is greater than the number of games lost"<< endl;
        else if (losses == wins)
            cout << "The number of games lost is equal to the number of games won" << endl;
        else if (losses < wins)
            cout << "The number of games tied is not greater than the number of games lost" << endl;

        cout << "The final team score is: " << final_score << "\n" << endl; //calculate the finals team score

    }
    cout << "Thanks you!"<< endl;


    //return 0; // this can be omitted; there isan implicit return 0 at the end of main
}
Thank you so much i really appreciate that i will take note of everything you have added or changed. and hopefully in the future I would be as kind and helpful as you are. Thanks.
Topic archived. No new replies allowed.