do/while loop

Hi! I am trying to have my program repeat with a do/while loop but when i put in the do/while i keep getting errors on it. This is a header file too and it works fine without the do/while but I still need to have it. Any tips? thank you!

Sample I/O:
Enter a sentence: The Last Project
In reverse order: tcejorP tsaL ehT
CONTINUE(Y/N)? y
Enter a sentence:....


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
#include <iostream>
#include <string>

using namespace std;

class MyClass
{
private:
	char a;
	stack<char> s;
	char ans;
public:
	MyClass(){};

	do
	{
	void readsentence()
	{
	cout << "Enter a sentence: ";
	while ( cin.get ( a ) && a != '\n' )
    s.push(a);
	}

	void showsentence()
	{
	cout << "In reverse order: ";
	while ( !s.empty() ) 
	{
    cout << s.top();
    s.pop();
	
	}
  cout <<'\n';

  cout << "CONTINUE(Y/N)? ";
  cin >>ans;
}
	}
	while (ans=='y'||ans=='Y')

};
You can't do it like that.

When you declare a class in a header file (as you've done), you're making a type. There shouldn't be any kind of actual executable code, since all you're doing is describing a type (your class) by giving it function declarations and other members.

You need to split your project into at least a couple files, however, it's recommended that you put the function implementations (function bodies) into a separate .cpp file.

oh okay
Topic archived. No new replies allowed.