1. ## if problem

Problem is when i press B as the center element the line at the end "if(centerelement=="B") should run what inside.

I put this inside the if statement:
Code:
```VEC = 3;
printf("%d",VEC);```
I put the printf so i can verify that the value of VEC is now 3.

Here is the source code:

Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{
char charselect[1];
int select;

char tempelement[3];

char centerelement[3];
char pelement1[3]; //periferal element 1
char pelement2[3]; //periferal element 2
char pelement3[3]; //periferal element 3
char pelement4[3]; //periferal element 4

int totalVE; //total valance electrons

int VEC; //# of valance electrons in center
int VE1;
int VE2;
int VE3;
int VE4;

/*	H = 1;
B = 3;
C = 4;
N = 5;
P = 5;
O = 6;
S = 6;
Se = 6;
F = 7;
Cl = 7;
Br = 7;
I = 7;
*/

printf("What is the structure of the Lewis Structure?\n\n");
printf("1 - Tetrahedral\n\n");
printf("Input corresponding number: ");
gets (charselect);
select = atoi(charselect);

if (select == 1)
{
printf("You selected Tetrahedral.\n\n");
printf("What is the center Element? \n");
scanf("%s",centerelement);
printf("What is the 1st periferal element? \n");
scanf("%s",pelement1);
printf("What is the 2nd periferal element? \n");
scanf("%s",pelement2);
printf("What is the 3rd periferal element? \n");
scanf("%s",pelement3);
printf("What is the 4th periferal element? \n");
scanf("%s",pelement4);

if(centerelement=="B")
{
VEC = 3;
printf("%d",VEC);
}

printf("%s %s %s %s %s", centerelement, pelement1, pelement1, pelement1, pelement1);
}
}```

2. You can't compare strings with the == operator. Try using strcmp. It returns 0 when the strings are identical.

3. Code:
```Ah, this is what I get for reading only half of the book, being impatient/excited to try out something by myself...

I put:

Code:
int strcmp(centerelement,"B");
But getting an error, what is wrong with what I put? I did "#include <string.h>" on top.```
Nevermind, The example given was bad. I removed int from strcmp and put in "int compare;" then "compare = strcmp(centerelement,"B");"

Fixed it, thanks

4. No need for an intermediate variable, you can just do this...
Code:
```//  old way... if(centerelement=="B")

if (! strcmp(centerelement, "B"))
{
VEC = 3;
printf("%d",VEC);
}```
I generally advise that you always look for ways to simplify your code, never using anything that's not entirely necessary to get the job done...

5. First off...stop using gets()! It's insecure; view the FAQ here for why and how to fix it.

Secondly, make charselect a single char variable, rather than an array of length 1 (which is wrong, because then there's no room for the required null terminator).

Example code:

Code:
```#include <stdio.h>

int main(void)
{
char selection;
int c = 0;
printf("1 - Tetrahedral\n");
printf("Select one: ");
while (scanf("%c", &selection) != 1) {
while((c = getchar()) != '\n') ; /* Consume any leftover chars in the buffer */
printf("Invalid selection!\nSelect one: ");
}
while((c = getchar()) != '\n') ; /* Consume any leftover chars in the buffer */
if (selection == '1') {
printf("You selected %c\n", selection);
} else {
printf("You selected %c, which is invalid!\n", selection);
}
return 0;
}```