Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Multiple functions

Multiple functions

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cstudent1
    wrote on last edited by
    #1

    Hi, I am hoping someone can help me with this. I need a program that counts char,vowels and words. I can get it to do all those things alone, but I am at a loss on how to make it all work together. Please help. Thanks! This is the program to count char, it works fine..... #include #include #define MAXNUM 1000 int countchar(char[]); int main() { char message [MAXNUM]; int numchar; printf("\nType in any number of characters : "); gets(message); numchar = countchar(message); printf("\nThe number of characters is %d",numchar); return 0; } int countchar(char list []) { int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } This is the program to count vowels, it worked fine until i tried to add the char count..... #include int main() { char str, line[150]; int i,v,c,ch,d,s,o,l, countchar, count, list; o=v=c=ch=l=d=s=0; printf("Enter a line of string:\n"); gets(line); for(i=0;line[i]!='\0';++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') ++v; } { int countchar(char list []) int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } printf("Vowels: %d",v); printf("characters %d",countchar); return 0; }

    OriginalGriffO L 2 Replies Last reply
    0
    • C cstudent1

      Hi, I am hoping someone can help me with this. I need a program that counts char,vowels and words. I can get it to do all those things alone, but I am at a loss on how to make it all work together. Please help. Thanks! This is the program to count char, it works fine..... #include #include #define MAXNUM 1000 int countchar(char[]); int main() { char message [MAXNUM]; int numchar; printf("\nType in any number of characters : "); gets(message); numchar = countchar(message); printf("\nThe number of characters is %d",numchar); return 0; } int countchar(char list []) { int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } This is the program to count vowels, it worked fine until i tried to add the char count..... #include int main() { char str, line[150]; int i,v,c,ch,d,s,o,l, countchar, count, list; o=v=c=ch=l=d=s=0; printf("Enter a line of string:\n"); gets(line); for(i=0;line[i]!='\0';++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') ++v; } { int countchar(char list []) int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } printf("Vowels: %d",v); printf("characters %d",countchar); return 0; }

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      And what, pray, does that have to do with C#?

      Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • C cstudent1

        Hi, I am hoping someone can help me with this. I need a program that counts char,vowels and words. I can get it to do all those things alone, but I am at a loss on how to make it all work together. Please help. Thanks! This is the program to count char, it works fine..... #include #include #define MAXNUM 1000 int countchar(char[]); int main() { char message [MAXNUM]; int numchar; printf("\nType in any number of characters : "); gets(message); numchar = countchar(message); printf("\nThe number of characters is %d",numchar); return 0; } int countchar(char list []) { int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } This is the program to count vowels, it worked fine until i tried to add the char count..... #include int main() { char str, line[150]; int i,v,c,ch,d,s,o,l, countchar, count, list; o=v=c=ch=l=d=s=0; printf("Enter a line of string:\n"); gets(line); for(i=0;line[i]!='\0';++i) { if(line[i]=='a' || line[i]=='e' || line[i]=='i' || line[i]=='o' || line[i]=='u' || line[i]=='A' || line[i]=='E' || line[i]=='I' || line[i]=='O' || line[i]=='U') ++v; } { int countchar(char list []) int i, count = 0; for(i=0; list[i] != '\0'; i++) count++; return(count); } printf("Vowels: %d",v); printf("characters %d",countchar); return 0; }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Your first problem is that this is C++ code and you have posted in the C# forum. However ... You should create all the separate functions to perform a specific action, and return the appropriate count. You then call each one from main passing the string to it. Something like:

        int main()
        {
        int characterCount;
        int vowelCount;
        int digitCount;
        // etc

        char message \[MAXNUM\];
        
        printf("\\nType in any number of characters : ");
        gets(message);
        
        characterCount = CountCharacters(message);
        vowelCount = CountVowels(message);
        digitCount = CountDigits(message);
        
        // print the values
        
        return 0;
        

        }

        Then you just have to write each function to do the counting and return the total.

        C 2 Replies Last reply
        0
        • L Lost User

          Your first problem is that this is C++ code and you have posted in the C# forum. However ... You should create all the separate functions to perform a specific action, and return the appropriate count. You then call each one from main passing the string to it. Something like:

          int main()
          {
          int characterCount;
          int vowelCount;
          int digitCount;
          // etc

          char message \[MAXNUM\];
          
          printf("\\nType in any number of characters : ");
          gets(message);
          
          characterCount = CountCharacters(message);
          vowelCount = CountVowels(message);
          digitCount = CountDigits(message);
          
          // print the values
          
          return 0;
          

          }

          Then you just have to write each function to do the counting and return the total.

          C Offline
          C Offline
          cstudent1
          wrote on last edited by
          #4

          This is supposed to be c code, I used my C book as the base of the code.Thanks for the tips. Can you help me with the counting? I think the problem I am running into is that I used i once for example when counting vowels and can not use it again when counting words. I'm really stuck here.

          1 Reply Last reply
          0
          • L Lost User

            Your first problem is that this is C++ code and you have posted in the C# forum. However ... You should create all the separate functions to perform a specific action, and return the appropriate count. You then call each one from main passing the string to it. Something like:

            int main()
            {
            int characterCount;
            int vowelCount;
            int digitCount;
            // etc

            char message \[MAXNUM\];
            
            printf("\\nType in any number of characters : ");
            gets(message);
            
            characterCount = CountCharacters(message);
            vowelCount = CountVowels(message);
            digitCount = CountDigits(message);
            
            // print the values
            
            return 0;
            

            }

            Then you just have to write each function to do the counting and return the total.

            C Offline
            C Offline
            cstudent1
            wrote on last edited by
            #5

            I am trying what you suggested and now I get the errors countChar can not be used as a function and, invalid types of int for array. I am really lost.

            L 1 Reply Last reply
            0
            • C cstudent1

              I am trying what you suggested and now I get the errors countChar can not be used as a function and, invalid types of int for array. I am really lost.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I would suggest you go back to your C reference and work slowly through the examples. If you do not understand the basics of writing functions then you are not going to get very far. Also, when you have further questions please use the C++ forum.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups