Error in C++ Program Help Please

Any Suggestions For why this won't debug properly.

//displays the weekly gross pay for any employee

#include <iostream>
using namespace std;

int main()
{
std::cout << "\nHourly workers pay:\n";
//Get hourly rate

std::cout << "Hourly rate: $";
double rate;
std::cin >> rate;
//Get hours worked

std::cout << "Hours worked: ";
double hours;
std::cin >> hours;

//calculate pay
double pay;

//check for overtime
if(hours > 40.0)

{
//standard rate
pay += rate * 40;

//overtime rate
pay += (rate * 1.5) * (hours - 40);
}

else
pay += rate * hours;

//results
if(std::cin.good())
std::cout << "The hourly workers pay is: $" << pay << "\n" << std::endl;
return 0;
}


I keep getting this code and a error.

1>------ Build started: Project: Introductory 18 Project, Configuration: Debug Win32 ------
1> Introductory18.cpp
1>c:\cpp8\chap 07\introductory 18 project\introductory 18 project\introductory18.cpp(30): warning C4700: uninitialized local variable 'pay' used
1> Introductory 18 Project.vcxproj -> C:\Cpp8\Chap 07\Introductory 18 Project\Debug\Introductory 18 Project.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
@tennisnash2

I believe the reason for your program not running, was given to you by the error codes

1>c:\cpp8\chap 07\introductory 18 project\introductory 18 project\introductory18.cpp(30): warning C4700: uninitialized local variable 'pay' used

Initialize the variable pay

pay = 18.50; or whatever..
How would I fix this error code.
@tennisnash2

Initialize pay with 0.0 to start. The program ran fine afterwards, for me..

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
#include <iostream>
using namespace std;

int main()
{
	std::cout << "\nHourly workers pay:\n";
	//Get hourly rate

	std::cout << "Hourly rate: $";
	double rate;
	std::cin >> rate;
	//Get hours worked

	std::cout << "Hours worked: ";
	double hours;
	std::cin >> hours;

	//calculate pay
	double pay = 0.0; // Initialize pay with 0.0 

	//check for overtime
	if (hours > 40.0)

	{
		//standard rate
		pay += rate * 40;

		//overtime rate
		pay += (rate * 1.5) * (hours - 40);
	}

	else
		pay += rate * hours;

	//results
	if (std::cin.good())
		std::cout << "The hourly workers pay is: $" << pay << "\n" << std::endl;
	return 0;
}
Thank You!
Topic archived. No new replies allowed.