Please help with outputting a float value

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..!

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
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace 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;
	
}
Last edited on
You probably want to remove all those extra couts on lines 37 and 44.

cout << fixed << setprecision(2) << SAL << '\n';
closed account (D80DSL3A)
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.

EDIT: Sorry cire. I didn't see your post.
Last edited on
wow..... that really WAS a very newbie mistake. How did I not- ..nevermind... Thank you haha. That fixed the issue..!
Topic archived. No new replies allowed.