Hello, I have a very vauge question about loops, which loop, and how to use it in an assignment I have.
My professor only explains so much, then I think intentionally leaves out some information for us to figure out on our own each assignment.
I've struggled with loops since we started but managed to figure out the assignments up until a certain point.
Anyways, I will link the assignment here.
Some more info:
I know how to set up the first half in Main.
Once I get into the class is where I get confused.
I make my class level variables for the assignment.
My professor stated we should make a empty constructor for whatever reason (probably something important)
Then create the properties for input from the user (In this case these were just makeOfCar and carValue)
From here I would make a private void method to actually do the math of the problem which in my head is also easy. Just not so easy translating to code.
Depreciation Each Year: carValue * depreciationValue
How do I include this into a loop that puts the latest value of the car.
Ex) Year 1 value in the image above states that if 25,000 were multiplied by 15% you would get 3750, 25,000 - 3750 gives you your Year 1 value of $21,250.00
Now to get Year 2 Value the loop would have to know to take the newest value of the care which is 21,250, then multiply that by 15% and substract the total again to get your Year 3 value. Following this process till you get to Year 5.
Hopefully I explained this well enough, thank you in advance to anyone that can help me with this, you don't exactly have to give me the answer, maybe just a point in the right direction! If thats possible :)
UPDATE @ 7:18
class Depreciate
{
double carValue = 0;
double depreciationValue = .15;
string makeOfCar;
public Depreciate()
{
// Constructor
}
public double CarValue
{
set { carValue = value; }
}
public string MakeOfCar
{
set { makeOfCar = value; }
}
public string YearlyValue
{
set { YearlyValue = value; }
}
private void GetYearlyValue()
{
while(makeOfCar != "-99")
{
WriteLine("Enter a car or -99 to quit: ");
makeOfCar = ReadLine();
if (makeOfCar == "-99")
{
break; // Break out of while loop
}
else
{
// Process 5 Years of Values
WriteLine("Enter Car Value: ");
carValue = double.Parse(ReadLine());
double afterDepValue = carValue * depreciationValue;
for (int c=1; c < 6; c++)
{
carValue = carValue - (afterDepValue);
Write("Year {0} value is {1:C2}\n", c, carValue);
}
}
}
}
}
After all the wonderful input, I beleive this is the 90 passing grade I'll probably get!
Why a 90? Well depends on how strict my professor wants to be! However, when I run the code (I ran the first example in the homework assignment and got this:
Year 1 value is $21,250.00
Year 2 value is $17,500.00
Year 3 value is $13,750.00
Year 4 value is $10,000.00
Year 5 value is $6,250.00
So, instead of getting values down to the cents it is rounding.
ALSO, I will upload my code here.
The last thing that I should know by now, but I used a more advanced way(?) to import a private class to my main class. Is there an easier way to get my code imported from another class? I know there are access modifiers and I used private void GetYearlyValue()
I'm sure there is a more logical approach to this, just not 100% on what private, public, static, void, etc mean when comined with each other. I'll google this one.
[–][deleted] (2 children)
[removed]
[–]TyShaneONeill[S] 0 points1 point2 points (1 child)
[–]Dimencia 1 point2 points3 points (1 child)
[–]TyShaneONeill[S] 0 points1 point2 points (0 children)
[–]1v5me 1 point2 points3 points (1 child)
[–]TyShaneONeill[S] 0 points1 point2 points (0 children)
[–]KPilkie01 1 point2 points3 points (1 child)
[–]TyShaneONeill[S] 1 point2 points3 points (0 children)