Skip to main content
added 171 characters in body
Source Link
UpAndAdam
  • 1.7k
  • 1
  • 3
  • 20

Introduction

Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.

Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.

You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.

Test your code

There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing

That said here are some things I found to help you.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness but is a good practice.

  2. countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is broken. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word.

If this answers your question, please click on the check mark to accept it. Please consider upvoting the answer as well if it was useful. This helps with site maintenance.

Introduction

Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.

Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.

You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.

Test your code

There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing

That said here are some things I found to help you.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness but is a good practice.

  2. countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is broken. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word.

Introduction

Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.

Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.

You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.

Test your code

There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing

That said here are some things I found to help you.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness but is a good practice.

  2. countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is broken. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word.

If this answers your question, please click on the check mark to accept it. Please consider upvoting the answer as well if it was useful. This helps with site maintenance.

added 1393 characters in body
Source Link
UpAndAdam
  • 1.7k
  • 1
  • 3
  • 20

Introduction

Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.

Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.

You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.

Test your code

There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing

That said here are some things I found to help you.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness but is a good practice.

  2. Your countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is wrongbroken. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use ). you also define but don't use is_wordis_word`.

my suggestion would be to make use of is_word to help you with this. i would consider figuring out when you go from not a word to a word and marking is_word true and incrementing your word count based on your approach, then when you determine that the word has ended mark is_word false again. Now you only have to look at the current character instead of a lookback.

Finally, there is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness.

  2. Your countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is wrong. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word`.

my suggestion would be to make use of is_word to help you with this. i would consider figuring out when you go from not a word to a word and marking is_word true and incrementing your word count based on your approach, then when you determine that the word has ended mark is_word false again. Now you only have to look at the current character instead of a lookback.

Finally, there is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem.

Introduction

Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.

Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.

You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.

Test your code

There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing

That said here are some things I found to help you.

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness but is a good practice.

  2. countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is broken. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word.

Source Link
UpAndAdam
  • 1.7k
  • 1
  • 3
  • 20

  1. Instead of doing for loops bound by condition of text[i] != '\0' just use a i < strlen(text) check like you used in countWord in your other functions. This is a minor thing that won't change overall correctness.

  2. Your countSentence is broken. Two problems. Your starting value of is_sentence. How many sentences are there if the first character is a . or if the whole string is ...? Additionally your condition is wrong, : does not delineate a sentence according to the instructions.

  3. Your countWord function is wrong. The instructions literally tell you as an example that sister-in-law should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check for i == 0 before your lookback is indeed correct). you also define but don't use is_word`.

my suggestion would be to make use of is_word to help you with this. i would consider figuring out when you go from not a word to a word and marking is_word true and incrementing your word count based on your approach, then when you determine that the word has ended mark is_word false again. Now you only have to look at the current character instead of a lookback.

Finally, there is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem.