An Idiotic Newb fails at a program...(Please help!)

Hello C++ Forum! I am a (relatively) new programmer, and have a fiendish curiosity with everything computers. That being said, I received the following error when attempting to run one of my first real codes.

[Error] expected 'while' before '}' token

I fixed this by adding the below to my code:
while (a!="shutdown_maiframe)

However, now when running it I received this error!
[Error] ISO C++ forbids comparison between pointer and integer [-fpermissive]

Here is my code, and I have inserted the name of a friend, who's identity has been censored.
---------------------------------------------------------
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main ()
{
string ms;
int a;
cout << "A.A.A. MAINFRAME \nPLEASE ENTER PASSWORD: ";
getline (cin,ms);
stringstream(ms) >> a;
if (a != 648)
cout << "PASSWORD DENIEDAAOSDKFJ;Oaldskjfakj234\nHACKING...\nHACK SUCCESFUL!\n";
cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS \n3. NEWS\n";
getline (cin,ms);
stringstream (ms) >> a;
do {
if (a==1)
cout << "Hello, and welcome back to the A.A.A.\n I will remain anonymous, but you should know that you are special. \n No one else in A.A.A. history has failed the reality test, and been recalled\n."
<< "Let me explain. The final test for an aspiring A.A.A. agent is to tell them that everything is fake, and see how they react. If they pass (which you didn't )\n"
<< "they join the A.A.A. However, no one EVER has been excepted into the company after failing. You have bypassed this, because of your...talents. Let us begin. View your missions. \nEND TRANSMISSION";
cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS \n3. NEWS\n";
getline (cin,ms);
stringstream (ms) >> a;
if (a==2)
cout << "A.A.A. MISSION SHEET\nASSIGNED FOR AGENT NAME *****\nMISSION STATUS: HOSTILE, DANGEROUS, AND EXTREMELY LETHAL. CAUTION ADVISED.\n";
cout << "MISSION DESCRIPTION AS FOLLOWS:\n ALL AGENTS: WE HAVE A CODE RED! A.A.A. SUBJECT -1 HAS ESCAPED OUR RECENT CAPTIVITY.\n"
<< "ALL FIELD AGENTS ARE TO REPORT TO THE NEAREST A.A.A. CENTER FOR IMMEDIATE RE-DEPLOYMENT. \nFAILURE TO DO SO WILL RESULT IN IMMEDIATE TERMINATION.\nEND TRANSMISSION";
cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS\n3. NEWS\n";
getline (cin,ms);
stringstream (ms) >> a;
if (a==3)
cout << "A.A.A. OFFICIAL NEWS BROADCAST\nBREAKING NEWS!\nApparantly, A.A.A. Subject -1 has escaped recent activity!\nThough Subject -1's file has yet to be released ";
cout << "publicly, it is believed to be that -1 is A.A.A.'s first scientifically proven captured Mage/Sorcerer!\nStay tuned for more information!";
cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS\n3. NEWS\n";
getline (cin,ms);
stringstream(ms) >> a;

}
while (a!="shutdown_mainframe");

}

I've seen this error before on this and many other sites, but all the solutions don't really seem to relate to this specific problem!
I use Dev C++. Please Help!
(Another note: Because I am such a beginner, I have a need to learn everything, so please provide a full explanation and/or a link to the explanation with your solution! Thank you!)
Last edited on
a is of type int, "shutdown_mainframe" is of type char*. You compare apples to cars.
That's what I thought, but when I changed a to a char, it just gave me this error:

[Error] ambiguous overload for 'operator>>' (operand types are 'std::stringstream {aka std::basic_stringstream<char>}' and 'char')

What should I do?
Since a is an integer, it is not possible for it to ever be equal to "shutdown_mainframe".

It can be equal to 1, or 900012, or -7, but not "hello world".

The ms string, however, can certainly be equal to "shutdown_mainframe".

41
42
43
44
  }
  while (ms != "shutdown_mainframe");

}

Also, don't forget that indentation means nothing to the compiler. It's just for us humans.

Put everything that belongs together between curly braces:

1
2
3
4
5
6
  if (a = 2)
  {
    // do stuff
    // do more stuff
    // etc
  }

Hope this helps.
boxnuggets wrote:
Hey. I used the script. My only problem is, when I inserted it, the program didn't shutdown after I typed in the specified parameters. I said Ok to myself, and added:

if (ms=="shutdown_mainframe")

But then it occurred to me...
I don't know any code lines that cancel a program! Please help!

Post back instead of PMs for help on your thread.

I don't know why it didn't work. This works for me:

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

int main ()
{
  string ms;
  int a;
  cout << "A.A.A. MAINFRAME \nPLEASE ENTER PASSWORD: ";
  getline (cin,ms);
  stringstream(ms) >> a;
  if (a != 648)
    cout << "PASSWORD DENIEDAAOSDKFJ;Oaldskjfakj234\nHACKING...\nHACK SUCCESFUL!\n";
  cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS \n3. NEWS\n";
  getline (cin,ms);
  stringstream (ms) >> a;
  do
  {
    if (a==1)
      cout << "Hello, and welcome back to the A.A.A.\n I will remain anonymous, but you should know that you are special. \n No one else in A.A.A. history has failed the reality test, and been recalled\n."
           << "Let me explain. The final test for an aspiring A.A.A. agent is to tell them that everything is fake, and see how they react. If they pass (which you didn't )\n"
           << "they join the A.A.A. However, no one EVER has been excepted into the company after failing. You have bypassed this, because of your...talents. Let us begin. View your missions. \nEND TRANSMISSION";
    cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS \n3. NEWS\n";
    getline (cin,ms);
    stringstream (ms) >> a;
    if (a==2)
      cout << "A.A.A. MISSION SHEET\nASSIGNED FOR AGENT NAME *****\nMISSION STATUS: HOSTILE, DANGEROUS, AND EXTREMELY LETHAL. CAUTION ADVISED.\n";
    cout << "MISSION DESCRIPTION AS FOLLOWS:\n ALL AGENTS: WE HAVE A CODE RED! A.A.A. SUBJECT -1 HAS ESCAPED OUR RECENT CAPTIVITY.\n"
         << "ALL FIELD AGENTS ARE TO REPORT TO THE NEAREST A.A.A. CENTER FOR IMMEDIATE RE-DEPLOYMENT. \nFAILURE TO DO SO WILL RESULT IN IMMEDIATE TERMINATION.\nEND TRANSMISSION";
    cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS\n3. NEWS\n";
    getline (cin,ms);
    stringstream (ms) >> a;
    if (a==3)
      cout << "A.A.A. OFFICIAL NEWS BROADCAST\nBREAKING NEWS!\nApparantly, A.A.A. Subject -1 has escaped recent activity!\nThough Subject -1's file has yet to be released ";
    cout << "publicly, it is believed to be that -1 is A.A.A.'s first scientifically proven captured Mage/Sorcerer!\nStay tuned for more information!";
    cout << "What would you like to do today? \n\n1. MESSAGES\n2. MISIONS\n3. NEWS\n";
    getline (cin,ms);
    stringstream(ms) >> a;

  }
  while (ms!="shutdown_mainframe");

}
D:\prog\foo> a
A.A.A. MAINFRAME
PLEASE ENTER PASSWORD: hello
PASSWORD DENIEDAAOSDKFJ;Oaldskjfakj234
HACKING...
HACK SUCCESFUL!
What would you like to do today?

1. MESSAGES
2. MISIONS
3. NEWS
1
Hello, and welcome back to the A.A.A.
<clipped for space>
END TRANSMISSIONWhat would you like to do today?

1. MESSAGES
2. MISIONS
3. NEWS
2
A.A.A. MISSION SHEET
<clipped for space>
END TRANSMISSIONWhat would you like to do today?

1. MESSAGES
2. MISIONS
3. NEWS
3
A.A.A. OFFICIAL NEWS BROADCAST
<clipped for space>
Stay tuned for more information!What would you like to do today?

1. MESSAGES
2. MISIONS
3. NEWS
shutdown_mainframe

D:\prog\foo> _

Hope this helps.
Topic archived. No new replies allowed.