Program unexpectedly ends after function

I am studying Object-Oriented Programming Using C++ (Fourth Edition) by Joyce Farrell and I'm currently on Chapter 7 (focuses on using classes), exercise 3 by myself (wish I could find an irc channel or some kind of study group, but I hate debugging...)
There aren't any syntax errors, but my program oddly enough stops after around the code line 81. I can enter the data in, but the console will just close out like it's finished. I even typed apple.dataEntry() twice just to see if that function will actually repeat and it does. Any clue why it's doing that?
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
80
81
82
83
84
85
86
87
88
89
90
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

class GroceryItem{
private:
	int stockNum;
	double price;
	int quantityInStock;
	double totalValue;
	
	int askStockNum();
	double askPrice();
	int askQuantity();
	void total();
public:
	int getStockNum();
	double getPrice();
	int getQuantity();
	double getTotal();

	void dataEntry();
};

int GroceryItem::askStockNum(){
	int x;
	cout<<"How much stock is there? ";
	cin>>x;
	while(x < 1000 || x > 9000){
		cout<<"That number is not valid.  Please enter a value between 1000 and 9000.";
		cin>>x;
	}
	return x;
}

double GroceryItem::askPrice(){
	double x;
	cout<<"How much does this item cost? ";
	cin>>x;
	while(x <= 0){
		cout<<"That number is not valid.  Please enter a value greater than 0. ";
		cin>>x;
	}
	return x;
}
int GroceryItem::askQuantity(){
	int x;
	cout<<"How much is in stock? ";
	cin>>x;
	while(x <= 0){
		cout<<"That number is not valid.  Please enter a value greater than 0. ";
		cin>>x;
	}
	return x;
}

double GroceryItem::getTotal(){
	return totalValue;
}

void GroceryItem::total(){
	double x;
	totalValue = price * quantityInStock;
}

int GroceryItem::getStockNum(){return stockNum;}
double GroceryItem::getPrice(){return price;}
int GroceryItem::getQuantity(){return quantityInStock;}

void GroceryItem::dataEntry(){
	askStockNum();
	askPrice();
	askQuantity();
}

int _tmain(int argc, _TCHAR* argv[]){
	GroceryItem apple;
	void displayValues(GroceryItem);
	apple.dataEntry();
	apple.dataEntry();
	displayValues(apple);
	cout << "Press ENTER to continue...";
	cin.ignore( numeric_limits<streamsize>::max(), '\n' );
	return 0;}

void displayValues(GroceryItem x){
	cout<<"Number in stock: "<<x.getStockNum()<<endl<<"Price: $"<<x.getPrice()<<endl<<
		"Quantity in stock: "<<x.getQuantity()<<endl<<"Total: $"<<x.getTotal();
}
You say "the console will just close out like it's finished." Isn't that because it IS finished? After it gets the data, it displays it but then immediately ends, without giving you time to look at it. Your cin.ignore statement there seems to not stop the program from ending. Try other things, like cin.get() or just cin >>.
You're not assigning the return values of ask...() to anything.
@freddy Thanks. That line of code didn't occur to me, because it worked well in my other projects. I'm not sure why it's not working this time.

@helios I had overlooked that. I turned the ask...() into all void functions this time and made ... = x.
Topic archived. No new replies allowed.