Hi guys!
Really need some help with my school project!
I needed to create a program to compute federal personal income taxes.
Requirements that I am to follow:
"Your program should be modular, that is small blocks of code. (Later in the semester when we encounter functions, you will see how handy modular development can be.) You are to follow these specifications as closely as possible. You should have code blocks that do the following:
1. Input status code. You should use a do/while loop to control the input logic. You are to keep the user in the loop until the input is correct. You are to ensure that the status codes are as specified above.
2. Input taxable income. As in step 1, you are to use a do/while loop for this logic. You are to keep the user in the loop until the input is valid.Calculate the tax owned as a result of status code and taxable income. You are to use a switch statement for the appropriate logic for each status code. You should manually calculate several cases to ensure your program is performing correctly.
3. Display the results of the calculation step. You are to output the status code, the string description of the status code, the taxable income, and the total tax amount. You are to use appropriate formatting of the output.
4. You main loop should be a while loop that repeat steps 1 through 4 until the user enters a status code of 9 that will terminate the job."
What I came up with:
//***************************************************
//This Pogram computes federal personal income taxes.
//The filing status and income are input by the User.
//***************************************************
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int statusCode; //variable declaration for input
float taxableIncome;
float taxAmt;
//Prompt the User to enter filing status and income
while (statusCode !=9)
{
do
{
cout << "Enter your filing status by a number 1 through 4 where: "<< endl;
cout << " 1 = single" << endl;
cout << " 2 = married filing jointly" << endl;
cout << " 3 = married filing separately" << endl;
cout << " 4 = head of household" << endl;
cout << "Enter 9 if you want to end the process" << endl;
cin >> statusCode;
if (statusCode != 1 && statusCode != 2 && statusCode != 3 && statusCode != 4 && statusCode != 9)
cout << "Your filing status must be 1 through 4 or 9 if you want to end this program" << endl;
system("pause"); //pause system to see the results
return 0;
}
} //main function ends
It runs but showing: "Run-Time Check Failure #3 - The variable 'statusCode' is being used without being initialized." and when I put status to check my program it is showing statusCode as 0. Any idea why? ! I can't figure out what I am doing wrong =(
int statusCode; //variable declaration for input
statusCode has a random value. It might even has the value 9 and your program won't do anything at all. Best practice is to give all variables a value when you create them. int statusCode = 0;