Hi i'm new to C programming, and i have this homework which i need to do on compounding interest, i would like to know whats wrong.
it says, "Run-Time Check Failure #3 - The variable 'HoursWorked' is being used without being initialized." same with other variables.
below is my code. Please help me! Help appreciated :D
oh, and im using microsoft visual studio 2005, school default, cant upgrade. settings used its general settings.
#include <stdio.h>
#include <math.h>
#define FALSE 0
#define TRUE 1
void main (void)
{
int HoursWorked,Hours,Hour,userc,Y,Years,menu,million,done,millionare,settings_complete;
float MoneySpent,MoneyMade,MoneyLeftOver,MoneyLeft,MoneySpentI,PricePerHour,startbalance,Total,WeekMoneyMade,CI;
while(done = true) //While Loops
{
printf("This program calculates the compounded interest in each year.\n");
printf("\n Menu \n");
printf("1 - Settings\n");
printf("2 - Account Summary\n");
printf("3 - Quit\n");
printf("******************\n");
printf("Enter Your Choice:");
scanf("%d",&menu);
switch(menu)
{
case 1:
printf("\t Menu - Settings\n");
printf("1 - Edit - Money Per Hour\n");
printf("2 - Edit - Hours Worked\n");
printf("3 - Edit - Expenditures\n");
printf("4 - Edit - Current Interest\n");
printf("5 - Edit - Savings Menu\n");
printf("6 - Quit\n");
scanf("%d",&menu);
switch(menu) //Another switch structure
{
case 1:
printf("How much do you make an hour: ");
scanf("%d",&PricePerHour);
done=false;
break;
case 2:
printf("How many hours do you work a week? (1-168): ");
scanf("%d",&HoursWorked);
if ((HoursWorked <= 0) || (HoursWorked >= 168))
{
printf("Your Number was Invalid. Please enter a Number between (1-168):");
scanf("%d",&HoursWorked);
}
done=false;
break;
case 3:
printf("How much money do you plan on spending Weekly? ");
scanf("%d",&MoneySpent);
if (0 > MoneySpent)
{
printf("Your Number was Invalid. A Positive Number Please: ");
scanf("%d",&MoneySpent);
}
done=false;
break;
case 4:
printf("What is the Current Interest Rate? ");
scanf("%d",&CI);
if (0 > CI)
{
printf("Your Number was Invalid. A Positive Number Please: ");
scanf("%d",&CI);
}
done=false;
break;
case 5:
{
printf("\\t Menu - Savings\n");
printf("1 - Years\n");
printf("2 - Edit Account Balance\n");
printf("3 - Millionare");
printf("4 - Quit");
scanf("%d",&menu);
switch(menu)
{
case 1:
printf("How Many Years would you like to have the total savings calculated for\n");
printf("(Any Number Greater then 1, 0 if You dont Wish To use this option):");
scanf("%d",userc);
done=false;
break;
case 2:
printf("What is the Current Balance of Your Account? \\n");
printf("(Any Number Greater then 1, 0 if You dont Wish To use this option): \\n");
scanf("%f",&startbalance);
done=false;
break;
case 3:
printf("Type 1, if you would like to calculate the time needed to become a millionare.");
printf("0 for No.");
scanf("%d",&million);
if (million=1)
{millionare=true;}
else
{millionare=false;}
done = false;
case 4:
done=true;
break;
default:
printf("You Have Enter an Invalid Choice. ");
done=false;
break;
done=false;
break;
}
case 6:
done=true;
break;
default:
printf("You Have Enter an Invalid Choice. ");
done=false;
break;
}
while (done=true);
{
settings_complete = true;
done=false;
break;
}
}
case 2:
if(settings_complete = true)
{
{
if (millionare=true)
{
{
int short Y,Z;
float X,Xvariable,Yvariable;
// Calculates Total Hours Worked During the Year
Hours = HoursWorked * 56;
Hour = HoursWorked;
// This then Calculate How Much Money Was made (Weekly & Yearly)
MoneyMade = PricePerHour * Hours;
WeekMoneyMade = PricePerHour * Hour;
// Simply calculation the money spent to a yearly value
MoneySpentI = MoneySpent * 56;
// Calculates the Net Profit (Weekly & Yearly)
MoneyLeftOver = MoneyMade - MoneySpentI;
MoneyLeft= WeekMoneyMade -MoneySpent;
// Initializes Required Variables For the Following Calculations
X = MoneyLeftOver;
Z = 0; //Control Variable for the second statement
Y = 0; //Control Variable for the first statement
Years = 0; //You dont make money before you begin the year, but after the loop goes around once
//The value is increased to 1
Yvariable = MoneyLeftOver; //Transfers the value to another variable to prevent a change to the main variable
Xvariable = startbalance; //See Above
// Annual Interest (Salary)
do //A do/while loop
{
Yvariable = ((Y * MoneyLeftOver) * CI) + X;
Y++;
Years++;
}
while (userc = Y + 1);
// Annual Interest (Initial Bank Balance)
do
{
Xvariable = ((Z * startbalance) * CI);
Z++;
}
while (userc = Z + 1);
// Account Balance plus the sum of the salary balance;
Total = Yvariable + Xvariable;
} ;
}
else
{
int short Y,Z;
float X,Xvariable,Yvariable;
// Calculates Total Hours Worked During the Year
Hours = HoursWorked * 56;
Hour = HoursWorked;
// This then Calculate How Much Money Was made (Weekly & Yearly)
MoneyMade = PricePerHour * Hours;
WeekMoneyMade = PricePerHour * Hour;
// Simply calculation the money spent to a yearly value
MoneySpentI = MoneySpent * 56;
// Calculates the Net Profit (Weekly & Yearly)
MoneyLeftOver = MoneyMade - MoneySpentI;
MoneyLeft= WeekMoneyMade -MoneySpent;
// Initializes Required Variables For the Following Calculations
X = MoneyLeftOver;
Z = 0;
Y = 0; //This is set to zero because you dont have a salary before the year begins
//But because of the loop the value after one loop is increased by 1(Y++)
Years = 0;
Yvariable = MoneyLeftOver;
Xvariable = startbalance;
// Annual Interest (Salary)
do
{
Yvariable = ((Y * MoneyLeftOver) * CI) + X;
Y++;
Years++;
}
while (userc = Y + 1);
// Annual Interest (Initial Bank Balance)
do
{
Xvariable = ((Z * startbalance) * CI);
Z++;
}
while (userc = Z + 1);
// Account Balance plus the sum of the salary balance;
Total = Yvariable + Xvariable;
}
}
}
else
{
printf("Please Edit The Settings Before Choosing this options.\n");
}
done=false;
break;
case 3:
done =true;
break;
default:
printf("You Have Enter an Invalid Choice.\n");
done=false;
}
}
}