primary expressions

Jul 12, 2008 at 1:19pm
this the program that im doing..
when i compile it i get the error
(expected primary expression before "char" in line 20
and storage size of "B" isn't known in line 12)
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
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string.h>
using std::operator>>;
#include <conio.h>

int main ()
{
    char A []  = "akire";
    char B [];
    
  
 
 
    cout << "\t\t\tGUESS A PASSWORD";
    
    cout << "\n\t\t        ";
    cin >> char B[];
    
    if (char B[] == char A[])
    cout << "\n\n\n\n\t\t CONGRATULATIONS!!! YOU HIT IT.." << endl;
    if (char B[] != char A[])
    cout << "\n\n\n\n\t\t MALI KA... BUTI NGA SAYO!!!" << endl;
    
   
    
    getch ();
    return 0;
    
}

Jul 12, 2008 at 2:50pm
delete the "char" in line 20.
Jul 12, 2008 at 2:53pm
I posted and article I wrote titled Arrays Revealed in the Articles forum. You should read that before trying to use arrays.
Jul 12, 2008 at 2:54pm
When you declare the "B" you use [] which means that it will be an array. To use this syntax you must initialize the array the same time (like "A"). Else you have to enter in the [] the size of your array.
When you use cin >> char B[]; you have to enter the position of the B array where you want to store the user's input. To read into an array you need a loop.
Also you shouldn't use the "char B[]" everywere you wantto use the B array bbecause itis syntax error. You should use B[position].
Last you cant compare arrays with (B[] == A[]). You need to check each value individually.

Hope that helps
Topic archived. No new replies allowed.