Variable ' ' not being initialized?

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
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
void main()

{
	//This program will help file and list monthly sales tax

	string month;
	int year;
	double collection;
	double sales;
	double totalTax;
	double SaleTaxState;
	double SaleCountyTax;
	const double StateTax=0.04;
	const double CountyTax=0.02;
	
	cout<<fixed<<showpoint<<setprecision(1)<<endl;
	cout<<"This is a Monthly Sales Tax Program. Please enter the month.\n";
	cin>>month;
	cout<<"Enter the year. \n";
	cin>>year;
	cout<<"What is the total amount you have collected in your register? \n";
	cin>>collection;

	sales=collection-totalTax;
	totalTax=SaleCountyTax+SaleTaxState;
	SaleCountyTax=(sales*CountyTax)-sales;
	SaleTaxState=(sales*StateTax)-sales;
	
	
	cout<<"Month: "<<month<<setw(6)<<year<<endl;
	cout<<"---------------------- \n";
	cout<<"Total Collected: "<<setw(9)<<collection<<endl;
	cout<<"Sales: "<<setw(9)<<sales<<endl;
	cout<<"County Sales Tax: "<<setw(9)<<SaleCountyTax<<endl;
	cout<<"State Sales Tax: "<<setw(9)<<SaleTaxState<<endl;
	cout<<"Total Sales Tax"<<setw(9)<<totalTax<<endl;
}


I can't really point out why the variable after my cin>>collection (including collection) are not being initialized, therefore not letting me run my program? Anyone notice the problem?

Thanks
-Nela
It doesn't look like you initialize or calculate totalTax before you use it. In fact, you calculate it on the line after:



sales=collection-totalTax;
totalTax=SaleCountyTax+SaleTaxState;
Thanks :D but I am still getting the error for SaleCountyTax & SaleTaxState.. eh, I have no idea why
What exactly is the error?

It helps to know more than "I'm getting errors."

All right, what I'm seeing: you're using SaleCountyTax & SaleTaxState, but these two variables are neither initialized nor calculated before hand.

I think perhaps you have the calculations out of order.


Also:

sales=collection-totalTax;

This is typically called a sub-total until it is actually recorded on the accounting books.
Last edited on
Oh sorry! It's "the variable is being used without being initialized" & its referring to my previous post
Ok, I need to work this out on paper(web paper) because it looks like you got yourself into a paradox here. NOTE: This is not in the order you need to calculate in a program.

collection = sales + totalTax;
totalTax = (TotalStateTax + TotalCountyTax);
TotalStateTax = sales * StateTax;
TotalCountyTax = sales * CountyTax
sales = collection - totalTax?

You have a problem here in that you can't know sales w/o knowing collection and you can't know collection w/o knowing sales.
Last edited on
I see, but the user inputs the collection...hmmmmmmmmmm
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
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;
void main()

{
	//This program will help file and list monthly sales tax

	string month;
	int year;
	double collection;
	double sales;
	double totalTax;
	double SaleTaxState;
	double SaleCountyTax;
	double StateTax;
    double CountyTax;
	StateTax=0.04;
	CountyTax=0.02;
	
	cout<<fixed<<showpoint<<setprecision(1)<<endl;
	cout<<"This is a Monthly Sales Tax Program. Please enter the month.\n";
	cin>>month;
	cout<<"Enter the year. \n";
	cin>>year;
	cout<<"What is the total amount you have collected in your register? \n";
	cin>>collection;


	totalTax=SaleCountyTax+SaleTaxState;
	sales=collection-totalTax;
	SaleCountyTax=(sales*CountyTax)-sales;
	SaleTaxState=(sales*StateTax)-sales;
	
	
	cout<<"Month: "<<month<<setw(6)<<year<<endl;
	cout<<"---------------------- \n";
	cout<<"Total Collected: "<<setw(9)<<collection<<endl;
	cout<<"Sales: "<<setw(9)<<sales<<endl;
	cout<<"County Sales Tax: "<<setw(9)<<SaleCountyTax<<endl;
	cout<<"State Sales Tax: "<<setw(9)<<SaleTaxState<<endl;
	cout<<"Total Sales Tax"<<setw(9)<<totalTax<<endl;
}


sale county tax and saletaxstate are still receiving errors.
thank you thank you for all your help!
My math is skewed..i see, i'll try another approach - if you see a fix, let me know :D
Topic archived. No new replies allowed.