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");
	}
What is your program all about?
@yandare i'm basically making a payroll program. However i'm having trouble doing pass by values since I fully don't get the concept despite looking up guides for it. So what you see in lines 6-8, 12-14, 16, 24 and 63 are my attempts at trying it. However it didn't work so i'm making this topic so that someone can give me easier / better examples to it based on this
Last edited on
why you wanna refer it to main as there is nothing left in main after write results
well like I said @Sajeel i'm not too familiar with how it works since I'm somewhat new to c++. So I have no idea how to do it the proper way.
closed account (E0p9LyTq)
Your functions pass variables in by reference, that is a good method.

You have several problems in main():

1. You can't declare a variable within a function call, it has to be declared before.

2. You have functions calls that are actually function declarations.

3. You are passing variables as pointers, not references.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
   string Yourname;
   float HourlyEarnings;
   float HoursWorked;
   float Grosspay;
   float TotalHours;
   double Overtime;
   double Taxes1;
   double Taxes2;

   AskName(Yourname);
   AskRateAndHours(HourlyEarnings, HoursWorked, Grosspay, TotalHours, Overtime, Taxes1, Taxes2);
   WriteResults(Yourname, HourlyEarnings, HoursWorked, Grosspay, TotalHours, Overtime,Taxes1, Taxes2);
}
@furryguy OH SO I'M SUPPOSED TO ADD ALL MY VARIABLES IN MAIN AGAIN AND REMOVE THE "float&" pointers (i think pointers is the term for it) in my functions. Now it works, thanks @furryguy for the help. Much appreciated :D
Last edited on
Topic archived. No new replies allowed.