Expected unqualified-id before '{' token

So, ive spent two days on this simple code, and i can't seem to figure out what "Expected unqualified-id before '{' token" means.
here is the code:



#include <iostream>
#include <cstdlib>
using namespace std;
int main(void);
{
cout <<"Please enter your first, middle, and last initials";
cin >>finit>> >>minit>> >>linit>>;
int factor
factor=
a=1;
b=2;
c=3;;
d=4;
e=5;
f=6;
g=7;
h=8;
i=9;
j=10;
k=11;
l=12;
m=13;
n=14;
o=15;
p=16;
q=17;
r=18;
s=19;
t=20;
u=21;
v=22;
w=23;
x=24;
y=25;
z=26;
cout <<"Your initial ID number is:";
cout <<finit<< <<minit<< <<linit<<;
system ("PAUSE");
return 0;
}
Your help is much appreciated as this is extremely frustrating.
You have an extraneous >> at the end of your cin line and an extraneous << at the end of your last cout.

[EDIT: And you have << << and >> >> in your cout and cin lines too. They should
be just << and >>]

What on earth is this code supposed to do anyway?
Last edited on
it gives you what we call an initial id number it is the six digit number of the values of all initials
most of the time it is six digits, but it can range from 3-6
You do know that the alphabet has ASCII values that you can use for numeric comparisons right?
i had no earthly idea
all i need to know is why the code gives me such an error. ive changed some things. look:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(void);
{; cout <<"Please enter your first, middle, and last initials";
cin >>finit minit linit;
int factor
factor=
a=1;
b=2;
c=3;;
d=4;
e=5;
f=6;
g=7;
h=8;
i=9;
j=10;
k=11;
l=12;
m=13;
n=14;
o=15;
p=16;
q=17;
r=18;
s=19;
t=20;
u=21;
v=22;
w=23;
x=24;
y=25;
z=26;
cout <<"Your initial ID number is:";
cout <<finit minit linit;
system ("PAUSE");
return 0;
}
i dont know what the **** is goin on but i need it to be fixed
and should i use something ither than' system ("PAUSE"); ' ?
The ; after int main(void) is what is giving you that first error. Remove it.
Well, you got a lot of errors here.

What are you trying to do (yes, about ID in numbers or someting like that, but how are you want to do it in your code)?

One error is in your beginning of main:
1
2
int main(void);
{;


This should be:
1
2
3
int main() //there is no need for void, aldo there is nothing wrong with it
{ //dont use ';' after main() and on this line after '{' 
//(after '{' doesnt cause an error, but there is no need for it) 


And I dont understand this:
1
2
3
4
int factor;
factor=
a=1;
//etc... 

What are you trying to do here?
welli removed the "int factor" and the "factor="
but the error still appears. here is the code now:


#include <iostream>
#include <cstdlib>
using namespace std;
int main();
{
cout <<"Please enter your first, middle, and last initials";
cin >>finit minit linit;

a=1;
b=2;
c=3;;
d=4;
e=5;
f=6;
g=7;
h=8;
i=9;
j=10;
k=11;
l=12;
m=13;
n=14;
o=15;
p=16;
q=17;
r=18;
s=19;
t=20;
u=21;
v=22;
w=23;
x=24;
y=25;
z=26;
cout <<"Your initial ID number is:";
cout <<finit minit linit;
system ("PAUSE");
return 0;
}
You don't cout or cin stuff like that...to cout or cin multiple things you do this:

1
2
3
int a = 0, b = 0, c = 0;
cin>>a>>b>>c;
cout<<a<<b<<c;
welli removed the "int factor" and the "factor="
but the error still appears. here is the code now

Did you even read his whole post?

1
2
3
int main() //there is no need for void, aldo there is nothing wrong with it
{ //dont use ';' after main() and on this line after '{' 
//(after '{' doesnt cause an error, but there is no need for it)  

Last edited on
Beside some (basic and important) mistakes, you got the logic of your program wrong.

You ask the user for input. Then you're trying to turn every letter into a number, just by writing 'a=1'. There is no way to do that as you're trying.

Do you know about arrays already? Then I would recommend you to use the following algorithm: create an array that contains all the letters of the alphabet, and use a for-loop to compare every element of the input with all the elements of this array. If there is a match, you got your number (the loop-counter, remember 'a' would give 0) and use it as output or store it into a variable or whatever.

You can use the ASCII numbers to, as jpeg mentioned, wich would be shorter and faster, but more complicated.

EDIT: thanks helios, i didnt noticed he had left the ; after main(). :)
Last edited on
I disagree with Scipio, and think that a x-'A' is as simple as it comes.
Last edited on
Well, maybe you're right. It's just that OP is clearly a beginner, and I'm afraid he will use things he dont understand, wich is Bad. On the other hand: this is probleblay also the case when he uses arrays.
But more important then the specific way how to do it, is a good logic behind the program. Now that isnt the case at all.
Just explain how, such that it will not be something he doesn't understand anymore...

Google an ASCII table and note that 'A' == 65. So, if you input a character, and subtract 65 from it, you would have a numeric value (equate) for the letter beginning with 'A' == 0.

1
2
3
4
char letter;
cin >> letter;
// if the letter is capital
letter -= 65;


Note that there are also lowercase letters in the ASCII table.
Yes, well, i think you're right after all. I just dont like ASCII because I dont know them that well, but I agree that isnt a valid reason to recommend others to avoid using it.

However, your code doesnt work correctly when I use it in a small program. Shouldnt you use getch() (from conio.h) to get the integer value of a key?
Whenever I see numerical literals where character literals would be more suitable, I have a sudden urge to throw diamond dust at the face of the programmer responsible. If the character code point is >=0x20 and <=0xFF in the UCS, prefer character literals. SPECIALLY if you expect the program to be used with code pages incompatible with ASCII; EBCDIC, most prominently.
Last edited on
Topic archived. No new replies allowed.