-4
#include <iostream>
#include <ctype.h>
    
using namespace std;
    
int countUpper (char*myString){    
    bool isupper(char s);

    size_t uCount{0};
    for(;*myString!='\0';){
        myString++; uCount++;
        isupper(true);
    }
    return uCount;
}

int main(){
    const char* myString= "Hello there world! How are you today?";

    int uCount= countUpper (myString );

    cout<<uCount<<"upper case letters in: \""<<myString<<"\""<<endl;
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770

1 Answers1

3

You are misusing isupper(). You have declared a function that you have not implemented. And you are ignoring the return value of that function.

Use std::isupper() instead, eg;

#include <iostream>
#include <cctype>

int countUpper (const char *myString){
    size_t uCount{0};
    for(; *myString != '\0'; ++myString){
        if (std::isupper(static_cast<unsigned char>(*myString)))
            ++uCount;
    }
    return uCount;
}

int main(){
    const char* myString = "Hello there world! How are you today?";

    int uCount = countUpper(myString);

    std::cout << uCount << "upper case letters in: \"" << myString << "\"" << std::endl;
    return 0;
}

Alternatively:

#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>

int countUpper (const std::string &myString){
    return std::count_if(myString.begin(), myString.end(),
        [](unsigned char ch){
            return std::isupper(ch):
        }
    );
}

int main(){
    const char* myString = "Hello there world! How are you today?";

    int uCount = countUpper(myString);

    std::cout << uCount << "upper case letters in: \"" << myString << "\"" << std::endl;
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770