Thanks,
I wasn't too sure where to put the new while statement
Code:
while(astring[i] != 'a' && astring[i] != '\0') i++;
and the if else loop.
edit:Now it just enters the string twice and the second time prints"you have an a!" regaurdless.
I need some input as to how to arrange the statements.
is this the correct order:
1. enter the string
2. perform string check with for statement
3. while != a and != /0
4. loop again
5. else print "your word contains an a"
I know this code below isn't in this order, I posted this before the edit when I thought it was working (before checking a few times)
Code:
int main(){
char astring[10]; //declare the array
int i = 0; //initialise the variable
// while (astring[i] != 'a' && astring[i] != '\0') i++;
{
printf("\nEnter a word:\n");
scanf("%s", astring); //put the string in a memory location, no &
while (astring[i] != 'a' && astring[i] != '\0') i++;
{
//for (i = 0; i <10; ++i) { // for (initial; condition; increment)
if (astring[i] != 'a') {
printf("\nEnter a word:\n");
scanf("%s", astring);
}
else (astring[i] == 'a'); { // if onr of the elemnts contain 'a'
printf("Your word contains a!\n");
}
}
}
}