Can you please tell me why this code will not work? I tried yours in taskgrader and it came back wrong but we have not covered some of the functions you wrote. This is a very basic and beginner course.
Can you please tell me why this code will not work? I tried yours in taskgrader and it came back wrong but we have not covered some of the functions you wrote. This is a very basic and beginner course.
#include <stdio.h>
int main (void){
char word[51];
int l=1;
int halfway;
int length=0;
char letter1='T';
char letter2='t';
int i=0;
scanf("%s",word);
while (word[i]!='\0'){
i++;
length=i;}
if (length%2==0){
halfway=length/2;
}else{
halfway=(length+1)/2;
}
while((word[l]!='\0') && ((word[l]!=letter1) && (word[l]!=letter2))){
l++;
if((word[l]!=halfway)&&((word[l]==letter1)&&(word[l]==letter2))){
printf("1");
}
else if ((word[l]!=halfway) && ((word[l]==letter1) && (word[l]==letter2))&&
(word[l]>=halfway)){
printf("2");
}
}
if(i%2!=0){
printf("1");
}else if ((word[l]!=letter1) && (word[l]!=letter2)){
printf("-1");
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
Hi,
Thank you so much for your help! Unfortunately, I am still getting a couple of issues. Would you be able to help me figure it out please? The code you gave, did not give a printf for "2" which is the letter is in the 2nd half of the word and the i+1 did not give an output of 1.
thank you!