typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };
electro account[10];
electro account[0].balance_due=$ 120.52;
electro account[0].address[50]={Cane Gardens};

Can someone tell em how to correct this piece of code. I'm using Codeblocks and it says it " expected an initializer before '.' " in the two last lines of this. It's not homework so please don't say your not going to do my homework for me. I did the program about a year ago, and just decided to fix the problem.

electro account[0].balance_due=$ 120.52; $ 120.52 is not a floating point value. The $ is an invalid digit. electro account[0].address[50]={Cane Gardens}; {Cane Gardens} is not a character array. Character arrays are designated "like this" (in quotes).

Thanks. I can't believe I missed that, and I changed that, but the error still shows up.

You don't need the "electro" on declare anything on lines 9 and 10, account[0] is already of type electro. I think you'll need a different tactic for copying the string in too.

You should use strcpy() function to copy the string. Try this :

typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };
electro account[10];
account[0].balance_due=120.52;
strcpy(account[0].address, "Cane Gardens");

I tried all th changes, but now t says "expected constructer, destructor or type conversion before '.' token" in line 9
and before the '(' in line 10

lines 8, 9 and 10 must be inside a function

#include <string.h>

typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };

int main()
{
    electro account[10];
    account[0].balance_due=120.52;
    strcpy(account[0].address, "Cane Gardens");

}

If i put it in a function, wouldn't it become local, and not accessible by the other functions?? It also indicates that when i put it in a function

you can move line 13 of the code I posted up above main(), but the other lines must be in a function.

Should I put it in a certain function?? I put the two lines in the main() function and the other before it but every instance where i try to use those values, it says that it wasn't declared. I was trying to make those values universal.

You will have to post the full code of the program you are attempting to write.

#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<string.h>
typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };
electro account[10];//The array is given ten members just for demonstration purposes.3
//Lines 13 and 14 are entered for demonstration purposes.

int electro_info()//This function allows a user to view a messeage from the management
{
    printf("The Electro Services Database was created so as to simplify the process of making\n");
    printf("basic transactions for the customers. It was first brought in as a way to satisfy\n ");
    printf("the need of the customers as brought forward by you, our dear customers. All tran-\n");
    printf("sactions made using this system are secure and legitimate and are immediatly pro-\n");
    printf("cessed upon completion of the transaction process.\n");
    printf("PLEASE NOTE:Any transaction which has been done but is wished to be undone should \n");
    printf("be reported within twelve(12) hours of the \n");
    printf("transaction.\n");
    int menu();
}
int view_balance()//This function allows the user can view any balances on their account.
{
    int password();
    printf("Your current balance is %d\n",account[0].balance_due);
    int menu();

}
int payment()//This function allows the user to make payments.
{
    printf("Please enter the name assigned to the account\n");
    scanf("%d",account[0].name);
    int paid,deposit;
    char response;
    int password();
    printf("Your current balance is %d\n",account[0].balance_due);
    printf("Are you going to be paying all of your balance now?\nY/N?\n");
    scanf("%c",&response);
    if(response=='Y'||'y')
    {
    account[0].balance_due=0.00;
    printf("Your account balance is now %d\n",account[0].balance_due);
    }
    else
    if(response=='N'||'n')
    {
        printf("Please enter the amount you are attempting to deposit\n");
        scanf("%d",&deposit);
        account[0].balance_due=account[0].balance_due-deposit;
        printf("The remaining balance in your account is now %d.\n",account[0].balance_due);
        printf("Thank you for using the Electro Services System........Goodbye\n");
    }

    return account[0].balance_due,deposit;
    int menu();
}
int processing(int balance, int deposit)
{
    FILE *file=fopen("C:\\Users\\Default User.DefaultUser-PC\\Desktop\\Computing programs\\Customer_Account.txt","a");
    printf("Your recent transaction is now being processed into the database. Please wait.\n");
    fprintf(file,"%c deposited &%d into account number %d",account[0].name[20],deposit,account[0].access_number);
    fclose(file);
}
int menu();
int password();
int welcome();
int main ()
{
system ("Color 74");
welcome();
password();
menu();
void duplication_check();
return 0;
getch();
}
int welcome()
{
    int i,x=0;

    printf("''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n");
    Sleep(500);
    printf("**            ** **** **      ****   ****       ***  ***    ****\n");
    Sleep(500);
    printf(" **    *     **  **   **     ****   **  **    **  ****  **  **  \n");
    Sleep(500);
    printf("  **  * *   **   **** **    ***    **    **   **   **   **  ****\n");
    Sleep(500);
    printf("   **** ****     **   *****  ***    **  **    **        **  **  \n");
    Sleep(500);
    printf("    **    **     **** *****   ****   ****     **        **  ****\n");
    Sleep(500);
    printf("                                                                \n");
    Sleep(500);
    printf(" 	****     ****       ****  **  **                           	\n");
    Sleep(500);
    printf("   	*   *   **  **     ***    ** **                             \n");
    Sleep(500);
    printf("   	****   ** ** **   ***     ****                              \n");
    Sleep(500);
    printf("   	*   * **      **   ***    ** **                             \n");
    Sleep(500);
    printf("   	****  **      **    ****  **  **                            \n");
    Sleep(500);
    printf("''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n");
    Sleep(1000);
    printf("(This program was written by Adrian King of the Electro Services Technological department)\n");
    printf("LOADING");
    while(x>3)
    {
    for(i=0;i>=3;i++)
    {
       printf(".");
    }
    system("cls");
    x++;
    };


}

int password()
{
    int password,counter=0;
    printf("Please enter the password\n");//The password is 8960
    scanf("%d",&password);
    while(counter==0)
    {
    if (password==8960){
    counter=1;
    printf("Welcome back User\n");

    }

    else
    if (password|=8960){
    printf("\bThat is the wrong password. Please try again\n");
    counter=0;
    scanf("%d",&password);
    }
    }
}
int menu ()
{
    int menu,value;
    printf("Welcome again  to the Electro Billing Computer Service\n");
    printf("Enter the number corresponding to the preferred option\n");
    printf("1-View your Electro bill balance\n");
    printf("2-Pay your Electro bill balance\n");
    printf("3-View the notice from the Electro Services management.\n");
    printf("4-Exit the system\n");
    scanf("%d",&menu);
    switch(menu)//This is a built-in function.It is a combination of several 'if' statements.
    {
        case 1:int view_balance();break;
        case 2:int balance_payment();break;
        case 3:int electro_info();break;
        case 4:value=0;int processing(int,int);printf("Thank You For Using The Electro Services Database......Goodbye.\n");break;
        default:printf("The Electro Services database does not contain an option related to the number entered\n");break;
    };
}
void duplication_check()
{
    int a=0,b=1,c=0,d=0;

    while(d<=11)
    {

        for(c=0;c<=10;c=c+1)
        {
            if(account[a].access_number==account[b].access_number)
            {

                account[b].name[20]='0';
                account[b].access_number=0;
                account[b].address[50]='0';
                account[b].balance_due=0;
                b++;
            }
            else
            b++;
        }
        d++;
    }
}

it's sort of a database-type program that I had to do about a year ago. I never got it to run, but it was printed so I never attempted to fix it till recently.

I am currently learning a bit in C++ and i have transposed most of this to C++. I don't know classes yet though, but any help will be accepted.

Line 86-110. What are you trying to write?

The two lines 13 and 14 are supposed to be the two giving the problems; the assignments.

Oh sorry, that was a sort of a loading screen kinda thing. It would print the words in astericks. It would end up printing "Welcome back" when it ended.

lines 160-163. The functions in those statements are NOT function calls, but function prototypes. If your intent is to call a function then remove the return type int, for example case 1:view_balance();break; Delete line 60 because it does nothing.

Now, where in all that code are you tring to put the two lines of code You posted in your original post that gave you the problems?

the int menu(); part is supposed to call the menu function.
I'll put up the edited version of the program.

#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<string.h>
typedef struct electro
{
    char name[20];
    int access_number;
    char address[50];
    float balance_due;
    };
electro account[10];//The array is given ten members just for demonstration purposes.3
electro account[0].balance_due=120.52;
electro account[0].address[50]="Cane Gardens";//Lines 13 and 14 are entered for demonstration purposes.

int electro_info()//This function allows a user to view a messeage from the management
{
    printf("The Electro Services Database was created so as to simplify the process of making\n");
    printf("basic transactions for the customers. It was first brought in as a way to satisfy\n ");
    printf("the need of the customers as brought forward by you, our dear customers. All tran-\n");
    printf("sactions made using this system are secure and legitimate and are immediatly pro-\n");
    printf("cessed upon completion of the transaction process.\n");
    printf("PLEASE NOTE:Any transaction which has been done but is wished to be undone should \n");
    printf("be reported within twelve(12) hours of the \n");
    printf("transaction.\n");
    int menu();
}
int view_balance()//This function allows the user can view any balances on their account.
{
    int password();
    printf("Your current balance is %d\n",account[0].balance_due);
    int menu();

}
int payment()//This function allows the user to make payments.
{
    printf("Please enter the name assigned to the account\n");
    scanf("%d",account[0].name);
    int paid,deposit;
    char response;
    int password();
    printf("Your current balance is %d\n",account[0].balance_due);
    printf("Are you going to be paying all of your balance now?\nY/N?\n");
    scanf("%c",&response);
    if(response=='Y'||'y')
    {
    account[0].balance_due=0.00;
    printf("Your account balance is now %d\n",account[0].balance_due);
    }
    else
    if(response=='N'||'n')
    {
        printf("Please enter the amount you are attempting to deposit\n");
        scanf("%d",&deposit);
        account[0].balance_due=account[0].balance_due-deposit;
        printf("The remaining balance in your account is now %d.\n",account[0].balance_due);
        printf("Thank you for using the Electro Services System........Goodbye\n");
    }

    return account[0].balance_due,deposit;
    int menu ();
}
int processing(int balance, int deposit)
{
    FILE *file=fopen("C:\\Users\\Default User.DefaultUser-PC\\Desktop\\Computing programs\\Customer_Account.txt","a");
    printf("Your recent transaction is now being processed into the database. Please wait.\n");
    fprintf(file,"%c deposited &%d into account number %d",account[0].name[20],deposit,account[0].access_number);
    fclose(file);
}
int menu();
int password();
int welcome();
int main ()
{
system ("Color 74");
welcome();
password();
menu();
void duplication_check();
return 0;
getch();
}
int welcome()
{
    int i,x=0;

    printf("''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n");
    Sleep(500);
    printf("**            ** **** **      ****   ****       ***  ***    ****\n");
    Sleep(500);
    printf(" **    *     **  **   **     ****   **  **    **  ****  **  **  \n");
    Sleep(500);
    printf("  **  * *   **   **** **    ***    **    **   **   **   **  ****\n");
    Sleep(500);
    printf("   **** ****     **   *****  ***    **  **    **        **  **  \n");
    Sleep(500);
    printf("    **    **     **** *****   ****   ****     **        **  ****\n");
    Sleep(500);
    printf("                                                                \n");
    Sleep(500);
    printf(" 	****     ****       ****  **  **                           	\n");
    Sleep(500);
    printf("   	*   *   **  **     ***    ** **                             \n");
    Sleep(500);
    printf("   	****   ** ** **   ***     ****                              \n");
    Sleep(500);
    printf("   	*   * **      **   ***    ** **                             \n");
    Sleep(500);
    printf("   	****  **      **    ****  **  **                            \n");
    Sleep(500);
    printf("''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n");
    Sleep(1000);
    printf("(This program was written by Adrian King of the Electro Services Technological department)\n");
    printf("LOADING");
    while(x>3)
    {
    for(i=0;i>=3;i++)
    {
       printf(".");
    }
    system("cls");
    x++;
    };


}

int password()
{
    int password,counter=0;
    printf("Please enter the password\n");//The password is 8960
    scanf("%d",&password);
    while(counter==0)
    {
    if (password==8960){
    counter=1;
    printf("Welcome back User\n");

    }

    else
    if (password|=8960){
    printf("\bThat is the wrong password. Please try again\n");
    counter=0;
    scanf("%d",&password);
    }
    }
}
int menu ()
{
    int menu,value;
    printf("Welcome again  to the Electro Billing Computer Service\n");
    printf("Enter the number corresponding to the preferred option\n");
    printf("1-View your Electro bill balance\n");
    printf("2-Pay your Electro bill balance\n");
    printf("3-View the notice from the Electro Services management.\n");
    printf("4-Exit the system\n");
    scanf("%d",&menu);
    switch(menu)//This is a built-in function.It is a combination of several 'if' statements.
    {
        case 1:view_balance();break;
        case 2:payment();break;
        case 3:electro_info();break;
        case 4:value=0;int processing(int,int);printf("Thank You For Using The Electro Services Database......Goodbye.\n");break;
        default:printf("The Electro Services database does not contain an option related to the number entered\n");break;
    };
}
void duplication_check()
{
    int a=0,b=1,c=0,d=0;

    while(d<=11)
    {

        for(c=0;c<=10;c=c+1)
        {
            if(account[a].access_number==account[b].access_number)
            {

                account[b].name[20]='0';
                account[b].access_number=0;
                account[b].address[50]='0';
                account[b].balance_due=0;
                b++;
            }
            else
            b++;
        }
        d++;
    }
}

The errors are in line 13 and 14. it says an initializer is needed before the '.'

Yes, as was said, 13 and 14 need to be placed in a function somewhere. Since your array is global (which isn't the best idea, but can be changed later) then they can go anywhere.

I had told you, you don't need the "electro" designation at the front of those two lines because account[0] is already of electro type.

Look at lines 60-61 for a minute. Firstly, you can only return one value, and secondly if you return from the function (line 60), the next line (61) is going to be skipped anyway.

You need to find a text or a good tutorial with a section on functions. You do not need the return type when calling them.

//headers, etc.
int return_int(int input);  /*prototype, need the type here */

int main(void)
{
   int y=2,z;
   z = return_int(y); /*calling the function, don't need the return type or the parameter type*/

   return 0;

}

int return_int(int input)  /*function definition, need the return type here */
{
    return (input-10);
}

I really never knew about the returning properly when I originally wrote this and i didn't notice it later on. I'll use a pointer to fix that, or a reference in C++.

Removing the electro was noted. i merely forgot to remove it cause the lines were deleted during editing.

Finding a GOOD tutorial about this is a problem too. They don't give me much info that i don't already know. And it's structures that I need help on apparently.

And isn't that how structures are declared?? I was taught to declare the struct as a universal and then put any assignments right after so that they would be accessible by all functions after. I'll take your advice and look for some tutorials though.

And isn't that how structures are declared??

The structure itself is more likely to be declared globally (though they can just as easily be declared within main or another function). The array of structs, maybe... but it's much safer to have that in main or somewhere else and pass it around via function parameters. When you are referring to specific members of a struct like account[0].yada, they have to be placed in one function or another, they can't just exist freely.

It's not a tutorial per se, but check out the C FAQ (http://c-faq.com/). It has a lot of good information on various sub-topics. Check out http://www.eskimo.com/~scs/cclass/cclass.html (scroll down and click on the intermediate notes, those start right at structures).

Thanks. I'll move them into the main then, and I'll check the links.

lines 30 and 32: You are still trying to invoke a function incorrectly. do not put the return type before the function name. If you want to call menu() then just say mainu(); -- not int menu() Remember: putting the return type before the function name makes it a function prototype, not a function call.

whenever I move the return type from them, it says that the function [menu(), password()] were not "declared in this scope".

add function prototypes at the beginning of the program, before the first function in the *.cpp file but after includes.

int main ()
{
account[0].balance_due=120.52;
account[0].address[50]={'C','a','n','e',' ','G','a','r','d','e','n','s','\0'};

Ok, so I moved the two lines into the main(), but now the one with the string now states that it needs a primary-expression and that it needs a ';' both before the '{' token. I have never gotten a proper legitimate definition to these terms on the net either, so I have no idea how to fix these, albeit the usually disappear after i move around a few things.

EDIT: I also put the function prototypes immediately after the header files and that fixed the scope problems

Look at what you are trying to do, you are trying to place a bunch of characters into a spot that is one past the end of the address array (it goes from indexes 0 to 49)

Check out strcpy to get the string into address, as someone had suggested above.

Look at what you are trying to do, you are trying to place a bunch of characters into a spot that is one past the end of the address array (it goes from indexes 0 to 49)

Check out strcpy to get the string into address, as someone had suggested above.

I don't understand what that means actually. And strcpy doesn't change anything

You have:

An array of structs, account that is type electro.
account[0] is the first of the structs
account[0].address is the character array (a C-string if it's null terminated)
account[0].address[50] would be the last [B]character[/B] of an array that's 51 members long, which is one more than your array has

You can't just redeclare address like that, it's already declared in the struct. Rather than try to copy it in character by character like that (which might work under some circumstances, I can't remember), you should just strcpy your initialization string into it

OK. now I see it. my logic was that the instant where i was copying in the string was the declaration and I was initializing the letter in it, which was not what is actually happening apparently.
The strcpy function copies from one array into another, so I would have to create another string and then copy it in then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.