我目前这段代码的问题与标点符号计数if语句有关。if(Text == '.' || Text == '!' || Text == '?')
.
我是否可以创建一个变量来代替 Text
在这种情况下,允许代码运行它的过程吗?
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
int main(void)
{ //Letter Count Section
string Text = get_string("Text: "); //Gets Text
char Checker = isalpha(Text); // Checks for letters
int Count = strlen(&Checker); //Counts letters
//Space Count Section
int Spaces = 0; //Declares Variable
if(isspace(Text)){ //Checks for Spaces
Spaces += 1; //Adds +1 to Variable if Space
}
//Punctuation Count
if(Text == '.' || Text == '!' || Text == '?')
Punctuation += 1;
float Sentence = (Count/(Spaces*100));
float Letters = (Punctuation/(Spaces*100));
printf("\n%f",Sentence);
printf("\n%f",Letters);
// Formula
int gradelvl = (0.0588 * Letters - 0.296 * Sentence - 15.8);
// End Result
printf("\nGradelevel: %i\n",gradelvl);
}