Cant see variable data !!! Please HELP!

Using the below code, I am running debug. I want to see the values as I enter data so have put several breaks in place. Once I enter a few values, I look at 'Autos' to see the values, or do a mouse-over on the variables, and neither gives me info. Is this because I am using a class or is there something else going on! thanks for any assistance!

Cheers
Ron

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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//prototypes
class FoodItem
{
	public:
		double points, protein, carbs, fat, fiber;
		double totPoints, totProtein, totCarbs, totFat, totFiber;
		string foodName;
		
		void CalculatePoints(string foodName, double protein, double carbs, double fat, double fiber)
		{
			double points = (protein / 10.9375) + (carbs / 9.2105) + (fat / 3.8889) - (fiber / 12.5);	

			cout << setprecision(2) << fixed << "Total points for " << foodName << " is " << points << endl;

			totPoints += points;
			totProtein += protein;
			totCarbs += carbs;
			totFat += fat;
			totFiber += fiber;
		};  

		void setInitialValue()
		{
			foodName = "abc";
			totPoints = 0.0;
			totProtein = 0.0;
			totCarbs = 0.0;
			totFat = 0.0;
			totFiber = 0.0;
		};

		void printTotal()
		{	
			cout << "\nTotal points for all food items are " << points << endl;
		}
};

int main()
{
	FoodItem myFood;

	myFood.setInitialValue();		//Clear initial total value

	double points = 0.0, 
		protein = 0.0, 
		carbs = 0.0, 
		fiber = 0.0,
		fat = 0.0;
	string foodName;

	do
	{
		cout << "Enter the following info to convert to points:\n";
		cout << "Enter Food Item" << endl;
		cin >> foodName;
		cout << "Enter protein: \n";
		cin >> protein;
		cout << "Enter carbs: \n";
		cin >> carbs;
		cout << "Enter fat: \n";
		cin >> fat;
		cout << "Enter fiber: \n";
		cin >> fiber;

		myFood.CalculatePoints(foodName, protein, carbs, fat, fiber);

	}while (foodName != "\0" || foodName != "");

	myFood.printTotal();

	system("pause");
	return 0;
};
your function FoodItem::setInitialValue() can be set in the constuctor of the class.
1
2
3
4
5
6
7
8
9
FoodItem()
{
          foodName = "abc";
          totPoints = 0.0;
	  totProtein = 0.0;
	  totCarbs = 0.0;
	  totFat = 0.0;
	  totFiber = 0.0;
};



also in the while statement (foodname != "\0" || foodname != "")

you are asking the compiler to check for the string "\0", which is backslash zero, and not NULL which is what i think you intend. to change this, use '\0'. Notice the apostrophes. this indicates a character, and not a string. By doing this you indicate a NULL.

what compiler are you using?
Microsoft Visual Studio 2010. I tried changing to ' ' and getting another error. All I wanted to do here is run the do loop until the foodName is empty.
pogrady, foodname is a std::string so calling operator!= with "\0" will check if the string contains only the byte value 0 as its sole character. This is perfectly valid, though obviously not what was intended.
Topic archived. No new replies allowed.