Why is my simple C++ "What is your name?" program not working?

1.6k views Asked by At

enter image description here

I keep getting the "undeclared identifier" error but I don't know what that means or how to fix this. Forgive me I am new to this!

#include <iostream>
#include <string>
using namespace std;

int main(void);
     //Not sure why there is a Parse issue?
{
     // insert code here...
     cout<< "Hello, what is your name?";
     cin>> Scotty;

     cout<< "Hello, "<<Scotty<<endl;

     return0;
 }

I was able to figure out the previous question of the undeclared identifier but now I am getting an 'Expected unqualified-id' error? Thanks for answering to those who have

2

There are 2 answers

0
Lokkesh On

Check this out :

#include <iostream>

using namespace std;

int main() {

string Scotty;
cout << " Hello what is your name";
cin >> Scotty;

cout <<"\nHello"<<Scotty<<endl;

}
0
Shine On

You haven't declared variable named Scotty. You must declare variables before use them so you must declare by adding string Scotty; before calling cin. Also you must replace the operator >> at the end of cin line to ;