Stacks Push and Pop

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
#include <iostream>
using namespace std;

class Stack
{

public:
	Stack();
	void Push(int stack[],int pushnumber);
	void Pop(int stack[],int popnumber);
	int top;
	void refreshstack(Stack &stack);
}
void Stack::Push(int stack[],int pushnumber){
Stack.top++;
stack[Stack.top] = pushnumber;

};
void Stack::refreshstack(Stack &stack){

	stack.top = -1;




};
void Stack::Pop(int stack[],int popnumber){
	popnumber = stack[Stack.top];
	Stack.top--;
}





int main(){
	int size = 10;
	int stack[10];
	Stack newstack;
	int pushnumber;
	int popnumber;
	int select;
	
	
	cout << "What do you want to do\n1)Push\n2)Pop\nExit\n";
	cin >> select;
	
	while (select !=3){
		switch(select){
		case 1:Push(stack,pushnumber);break;
		case 2:break;
		default:break;
		}
	}














	return 0 ;
}


Im trying to write a program which pushes and pops numbers into and out of a stack however Im having trouble calling my push function? any ideas
Last edited on
You aren't initializing any of your variables, pushnumber, popnumber, top...
yes I will initaalise them but how do I call push function

currently it says Push is undefined
1
2
3
4
5
6
7
	while (select !=3){
		switch(select){
		case 1:cin >> pushnumber;newstack.Push(stack,pushnumber);break;
		case 2:cin >> popnumber;break;
		default:break;
		}
	}

did this I get these errors

1
2
3
4
5
6
7
8
9
10
11
12
13
>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(14): error C2628: 'Stack' followed by 'void' is illegal (did you forget a ';'?)
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(14): error C2556: 'Stack Stack::Push(int [],int)' : overloaded function differs only by return type from 'void Stack::Push(int [],int)'
1>          c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(9) : see declaration of 'Stack::Push'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(14): error C2371: 'Stack::Push' : redefinition; different basic types
1>          c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(9) : see declaration of 'Stack::Push'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(15): error C2143: syntax error : missing ';' before '.'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(15): error C2143: syntax error : missing ';' before '.'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(16): error C2226: syntax error : unexpected type 'Stack'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(28): error C2226: syntax error : unexpected type 'Stack'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(29): error C2143: syntax error : missing ';' before '.'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(29): error C2143: syntax error : missing ';' before '.'
1>c:\users\faieq\documents\visual studio 2010\projects\stacks and queues\stacks and queues\stacks and queues.cpp(51): error C2264: 'Stack::Push' : error in function definition or declaration; function not called
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
bump
Your first error:
(did you forget a ';'?)

You have to end the class with a semi-colon
Topic archived. No new replies allowed.