Need help on calculations with variables

Hi I have only been learning C++ for a couple of weeks I need help on doing calculations with variables.

It is an exercise I have been given in class and I am now working on at home but I am not outputting the correct answers.

The question is:

A student is allocating his allowance for the 16 weeks of a course over the following areas:

Accommodation - total amount

Materials - one off payment

Food - 60% of remaining allowance

Entertainment - 40% of remaining allowance


Output a breakdown of the availiable money for the student ensuring that the food and entertainment is expressed as a weekly value.


I am getting the correct answer for the total amount for the accomadation but not for the remaining allowance for the Food & Entertainment. Here is the code I have.

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
#include "stdafx.h"
#include <conio.h>
#include <iostream>
#include <iomanip>

using namespace std;
 
int _tmain(int argc, _TCHAR* argv[])
{
	double StuAllow, AccWeeklyCost, MatCost, TtlCostAcc, Deducs, RemainAllow, FoodAll, EntAll, WeeklyEntAll, WeeklyFoodAll;
	double const FoodPerc = 0.6, EntPerc = 0.4;
	double const LengOfCourse = 16;

	cout << "\n\n\t\t\t\tStudent Weekly Allowance";
	cout << "\n\n\n\tPlease enter the amount of money that you have availiable: ";
	cin >> StuAllow;
	cout << "\n\n\tPlease enter the cost of the accomadation per week: ";
	cin >> AccWeeklyCost;
	cout << "\n\n\tPlease enter the cost of the materials required: ";
	cin >> MatCost;

	TtlCostAcc = AccWeeklyCost * LengOfCourse;
	Deducs = TtlCostAcc + MatCost;
	RemainAllow = StuAllow - Deducs;
	FoodAll = RemainAllow * FoodPerc;
	WeeklyFoodAll = FoodAll / LengOfCourse;
	EntAll = RemainAllow * EntPerc;
	WeeklyEntAll = EntAll / LengOfCourse;

	cout << "\n\n\tYour total cost for your accomadation will be " << TtlCostAcc;
	cout << "\n\n\tYour weekly allowance for food will be " << WeeklyEntAll;
	cout << "\n\n\tYour weekly allowance for entertainment will be " << WeeklyEntAll;
	cout << "\n\n\tPress any key to end the program.";

	_getche();
	return 0;
}
Looks like a copy/paste error? Lines 31 and 32 are both printing WeeklyEntAll. I think line 31 was supposed to be printing WeeklyFoodAll.
Thank you very much, silly mistakes are never good!
Topic archived. No new replies allowed.