Can't return to int main()

Hi, my function ( float WriteResults() ) is unable to return to main and i'm not sure how to refer them to main. Could someone help me with the problem, i'm somewhat new to C++ and if you find any other problems with solutions for it, please tell me.

*Edit
Alright after much editing, I tried to do pass by value etc but i'm unsure on what is the problem. Could someone help

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
#include <iostream>
	#include <cmath>
	#include <iomanip>
	#include <string>
	using namespace std;
	void AskName(string&Yourname);
	void AskRateAndHours(float&HourlyEarnings, float&HoursWorked, float&Grosspay, float&TotalHours, double&Overtime, double&Taxes1, double&Taxes2);
	void WriteResults(string&Yourname, float&HourlyEarnings, float&HoursWorked, float&Grosspay, float&TotalHours, double&Overtime, double&Taxes1, double&Taxes2);

	int main()
	{
		AskName(string&Yourname);
		AskRateAndHours(float&HourlyEarnings, float&HoursWorked, float&Grosspay, float&TotalHours, double&Overtime, double&Taxes1, double&Taxes2);
		WriteResults(Yourname,HourlyEarnings,HoursWorked,Grosspay, TotalHours,Overtime,Taxes1,Taxes2);
	}
	void AskName(string&Yourname)
	{
		cout << "What is your name?" << endl;
		cin >> Yourname;
		cout << "Welcome:" <<""<< Yourname << endl; 
		cout << setfill('-') << setw(50) << "-" << endl;
	}

	void AskRateAndHours(float&HourlyEarnings, float&HoursWorked, float&Grosspay, float&TotalHours, double&Overtime, double&Taxes1, double&Taxes2)
	{

		cout << "Enter your hourly earnings" << endl;
		cin >> HourlyEarnings;
		cout << "Enter your hours worked" << endl;
		cin >> HoursWorked;
		cout << setfill('-') << setw(50) << "-" << endl;

		// assuming that 1 working week = 5 days. (Monday - Friday)
		TotalHours = HoursWorked * 5;
		Grosspay = (HourlyEarnings*HoursWorked) * 5;
		Overtime = Grosspay*0.5;
		Taxes1 = Grosspay*0.1;
		Taxes2 = Grosspay*0.2;
		cout << "This is your total pay per week:" << "" << Grosspay << "$" << endl << endl;

		if (TotalHours > 40)
		{
			cout << "You are eligible for an added overtime bonus of:" << "" << Overtime << "$" << endl;
			cout << "This ammount will be added to your wage" << endl << endl;
		}

		if (Grosspay < 250)
		{
			cout << "You do not have to pay any taxes" << endl;
		}

		else if (Grosspay <= 500)
		{
			cout << "However, you have to pay a 10% tax worth:" << "" << Taxes1 << "$" << endl << endl;
		}

		else if (Grosspay > 500)
		{
			cout << "However, you have to pay a 20% tax worth:" << "" << Taxes2 << "$" << endl << endl; 
		}
	}

	void WriteResults(string&Yourname, float&HourlyEarnings, float&HoursWorked, float&Grosspay, float&TotalHours, double&Overtime, double&Taxes1, double&Taxes2)
	{
		cout << "Here are your results:" << endl << endl;
		cout << setfill('-') << setw(50) << "-" << endl;
		cout << "Name:" << Yourname << endl;
		cout << "Earnings per hour:" << HourlyEarnings <<"$"<< setprecision(2) << fixed << endl;
		cout << "Hours worked each day:" << HoursWorked <<""<< endl;
		cout << "Your total hours worked per week:" << TotalHours << endl;
		cout << "Your Grosspay:" << Grosspay <<"$"<< setprecision(2) << fixed << endl;
		cout << "Your Overtime bonus:" << Overtime <<"$"<< setprecision(2) << fixed << endl;
		if (Grosspay < 250)
		{
			cout << "Your Taxes are:" << "0" << "$" << setprecision(2) << fixed << endl << endl << endl;
		}

		else if (Grosspay <= 500)
		{
			cout << "Your Taxes are:" << Taxes1 << "$" << setprecision(2) << fixed << endl << endl << endl;
		}

		else if (Grosspay > 500)
		{
			cout << "Your Taxes are:" << Taxes2 << "$" << setprecision(2) << fixed << endl << endl << endl;
		}

		system("pause");
	}
Last edited on
Your AskRateAndHours function has a call to main() (line 67) which is forbidden by the c++ standard. Also you have declared your functions as returning floats but they should be voids.

So change lines 5, 6 and 7 to
1
2
3
void AskName();
void AskRateAndHours();
void WriteResults();


And delete lines 22, 67, 68 and 81.
Last edited on
I tried it, but the functions in WriteResults() are still considered undeclared
Last edited on
Did you delete the call to main()on line 67?
everything you said m8
Also all the variable you use in WriteResults() have gone out of scope by the time the program gets there, hence they are undefined. Either make them global( bad pratice but will work in this case) or pass them by value or refeerence.
Last edited on
If the prototypes at lines 5,6,7 changed to void, did the function definitions at lines 16, 25 and 71 also get changed to void?
well how would I do it using pass by value/reference? Because i'm not too familiar with this
Last edited on
@wildblue Yea, I changed it after that. But the problem now is that I have to do a pass by value/reference according to @Jims . And if I were to make them global, the debugger would do an infinite loop the moment I enter something at line 20.
Last edited on
Would 'Yourname' be a string, not an int?

@wildblue oh yea that, thanks, it managed to solve the loop error. Also forgive me if I reply late later. I'll get to you guys asap so yea
Last edited on
Topic archived. No new replies allowed.