I cant seem to get the two variables to add up to 100% even if the 2 variables are 2 different numbers they seem to come out to the same percentage when 1 should be higher than the other. please help
#include<iomanip>
#include<iostream>
using namespace std;
int main()
{
int Fe; // User enters input
int Ma; // User enters input
float average; // the calculated value
// prompt the user for input
cout << "Enter the number of females in class: ";
cin >> Fe;
cout << "Enter the number of males in class: ";
cin >> Ma;
// calculate the average
average = float(Fe + Ma) / 2;
// Display the output
cout << endl << endl << setprecision(2) << fixed;
cout << "The Precentage of females: "<< average << "%" << endl;
cout << "The precentage of males: " << average << "%" << endl << endl;
so in order for me to add the 2 averages up i would need to add what you provided onto the calculated value, or would i get rid of the previous value before
#include<iomanip>
#include<iostream>
using namespace std;
int main()
{
int Fe; // User enters input
int Ma; // User enters input
float average; // the calculated value
// prompt the user for input
cout << "Enter the number of females in class: ";
cin >> Fe;
cout << "Enter the number of males in class: ";
cin >> Ma;
// calculate the average
average = float(Fe + Ma) / 2;
float avgFe = static_cast<float>(Fe) / (Fe+Ma) * 100.0f;
float avgMa = static_cast<float>(Ma) / (Fe+Ma) * 100.0f;
// Display the output
cout << endl << endl << setprecision(2) << fixed;
cout << "The Precentage of females: "<< average << "%" << endl;
cout << "The precentage of males: " << average << "%" << endl << endl;
Well, before you were printing the variable 'average' for both lines. What are you printing now, if you're no longer calculating the average?
Are you printing the same thing for both lines? If so, why would you expect to the printed values to be different?
1 2 3 4
int a = 42;
int b = 24;
std::cout << "This is 42: " << a << std::endl;
std::cout << "Why isn't this 24?? " << a << std::endl;