Good evening. Im doing a project for class, and I cant seem to figure out why the "salary" output is showing up as, for example, 26000.00x47e748.0x47e748 - when all I want is 26000.00. I know it's a pretty newbie mistake, but I just can't figure out what I'm missing..!
#include <iostream>
#include <cstdlib>
#include <iomanip>
usingnamespace std;
#define ADULT 18 //Age (integer).
#define SMWD 1000.0 //Salary (float) Multiplier with degree.
#define SMWO 600.0 //Salary (float) Multiplier without degree.
int main()
{
system("CLS"); //Clear the screen.
int AGE; //Integer input for users age.
double SAL; //Final salary offer.
char YN; //Character input for college graduate status.
/* Intro. & Instructions */
cout << "\nJob Offer Salary Calculator\n\n";
cout << "This program requests the users age and\n";
cout << "college graduate status in order to\n";
cout << "calculate the salary they will be offered.\n\n";
/* Data input and output Section */
cout << "Thank you for applying today.\n";
cout << "Please enter your current age (EX: 26):";
cin >> AGE;
if (AGE >= ADULT)
{
cout << "Are you a college graduate? (Y/N):";
cin >> YN;
if (YN=='Y' || YN=='y')
{
SAL = AGE * SMWD; // If they are a graduate, multiply their age by constant "SMWD".
cout << "\nThank you for applying.\n";
cout << "Our yearly salary offer for you is: $";
cout << setprecision(2) << showpoint << fixed << SAL << cout << "." << cout << endl;
}
else
{
SAL = AGE * SMWO; // If they aren't a graduate, multiply their age by constant "SMWO".
cout << "\nThank you for applying.\n";
cout << "Our yearly salary offer for you is: $";
cout << setprecision(2) << fixed << SAL << cout << "." << cout << endl;
}
}
else
{
AGE = 18 - AGE; // If they are under 18, subtract their age from 18 and desplay remaining years.
cout << "\nWe appreciate your interest in our company,\n";
cout << "however you must be 18 or older to work here.\n";
cout << "Please come back and apply in " << AGE << " year(s).";
}
return 0;
}
I'm going to guess it's being caused by the multiple cout's on each output line.
Try correcting line 37 to: cout << setprecision(2) << showpoint << fixed << SAL << "." << endl;
Similarly for line 44.