Page 1 of 3 123 LastLast
Results 1 to 10 of 27

Thread: Homework help... Again.

  1. #1
    Join Date
    Aug 2011
    Beans
    38

    Question Homework help... Again.

    So i'm wirghting this program:

    PHP Code:
    #include <stdio.h>
    #include <iostream>

    int main()
    {
    char A,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
    printf ("Introduzca un caracter, por favor.");
    scanf("%c", &A);
    if (
    A==b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z)
    printf("Caracter es una consonante.");
    else (
    A==a,e,i,o,u)
    printf ("Caracter es una vocal.");
    else (
    A==%i)
    printf ("Caracter es un numero.");

    It's supposed to:

    1.-Ask you to input a (1) charecter/intager.
    2.- Then it should output wether if it's a consonant, vowel or integer.

    That's it, but I'm still having loads of trouble with characters, I can I get some orientation? Please.

  2. #2
    Join Date
    Dec 2011
    Location
    London
    Beans
    68
    Distro
    Ubuntu Studio 12.10 Quantal Quetzal

    Re: Homework help... Again.

    I have made a code in C which looks a bit like this

    Code:
    #include<stdio.h> #include<conio.h> #include<string.h> void main() {  char s[100];  int b,c,d,e,i,l,p;  b=c=d=e=0;  clrscr();  printf("\n\t Enter the string :=>");  gets(s);  l=strlen(s);  for(i=0;s[i]!='\0';i++)   {    if((s[i]>=65&&s[i]<=90||s[i]>=97&&s[i]<=122))    b++;    if(s[i]>=48&&s[i]<=57)    c++;    if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')    d++;       if (s[i]==' ')    e++;    }    p=b-d;    printf("\n\t No of vowels=%d \n",d);    printf("\n\t No of consonants=%d \n ",p);    printf("\n\t No of digits=%d \n",c);    printf("\n\t no of words=%d \n ",e+1);    printf("\n\t No of specal character=%d \n",l-b-c-e);
    getch();
    }
    The only thing is that this is not my complete version as my development version is on my mac which is currently not usable. I think that this would be pretty simple to recreate in php.. Good Luck
    Last edited by Cookieh; February 14th, 2012 at 09:04 PM. Reason: Tidy up the code

  3. #3
    Join Date
    Dec 2011
    Location
    London
    Beans
    68
    Distro
    Ubuntu Studio 12.10 Quantal Quetzal

    Re: Homework help... Again.

    Sorry, I can not get it to be in the formating which has indentations, hopefully you can solve it... Sorry

  4. #4
    Join Date
    Aug 2011
    Beans
    38

    Re: Homework help... Again.

    PHP Code:
    #include<stdio.h>
     #include<conio.h>
     #include<string.h>
     
    void main()
     {
      
    char s[100];
      
    int b,c,d,e,i,l,p;
      
    b=c=d=e=0;
      
    clrscr();
      
    printf("\n\t Enter the string :=>");
      
    gets(s);
      
    l=strlen(s);
      for(
    i=0;s[i]!='\0';i++)   {    if((s[i]>=65&&s[i]<=90||s[i]>=97&&s[i]<=122))    b++;
        if(
    s[i]>=48&&s[i]<=57)    c++;    if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')    d++;
           if (
    s[i]==' ')    e++;    }
        
    p=b-d;
        
    printf("\n\t No of vowels=%d \n",d);
        
    printf("\n\t No of consonants=%d \n ",p);
        
    printf("\n\t No of digits=%d \n",c);
        
    printf("\n\t no of words=%d \n ",e+1); 
       
    printf("\n\t No of specal character=%d \n",l-b-c-e);
    getch();

    I see what it does, but this is for a whole string, I just need it to be for one (1) char or int. I guess I could kind of re work it. Thank you. Giving me the answer is not the same as help though, can anyone tell me more or less what I'm doing wrong? Please.
    Last edited by rafaelcbf; February 14th, 2012 at 09:25 PM. Reason: More info.

  5. #5
    Join Date
    May 2006
    Beans
    1,790

    Re: Homework help... Again.

    Quote Originally Posted by rafaelcbf View Post
    So i'm wirghting this program:

    PHP Code:
    #include <stdio.h>
    #include <iostream>

    int main()
    {
    char A,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
    printf ("Introduzca un caracter, por favor.");
    scanf("%c", &A);
    if (
    A==b,c,d,f,g,h,j,k,l,m,n,p,q,r,s,t,v,w,x,y,z)
    printf("Caracter es una consonante.");
    else (
    A==a,e,i,o,u)
    printf ("Caracter es una vocal.");
    else (
    A==%i)
    printf ("Caracter es un numero.");

    It's supposed to:

    1.-Ask you to input a (1) charecter/intager.
    2.- Then it should output wether if it's a consonant, vowel or integer.

    That's it, but I'm still having loads of trouble with characters, I can I get some orientation? Please.
    I recommend that you read, refresh your memory or ask your teacher about these things:

    1) character constants

    2) tests and logical operators

    Your program seems to be intended to be C++, judging from the include files, but you should say so explicitly - many languages are discussed here.

  6. #6
    Join Date
    Aug 2011
    Beans
    38

    Re: Homework help... Again.

    Oh, sorry about that, yes this is c++.

  7. #7
    Join Date
    Jun 2007
    Location
    Paraparaumu, New Zealand
    Beans
    Hidden!

    Re: Homework help... Again.

    Quote Originally Posted by arndt View Post
    i recommend that you read, refresh your memory or ask your teacher about these things:

    1) character constants

    2) tests and logical operators
    Agreed
    The way the first listing reads to me is as if it is comparing variables, which is not necessarily the same thing as testing the variables against predefined values.

    If you do something like:
    if (A=b)....
    A and b are labels that refer to memory locations that could contain any information.
    Last edited by lisati; February 14th, 2012 at 09:38 PM.
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  8. #8
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Homework help... Again.

    Quote Originally Posted by rafaelcbf View Post
    Oh, sorry about that, yes this is c++.
    If it is C++ then you should not really use stdio (that is C), and you should use cin and cout (with the >> and <<) operators for input and output).
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

  9. #9
    Join Date
    May 2006
    Beans
    1,790

    Re: Homework help... Again.

    Quote Originally Posted by Tony Flury View Post
    If it is C++ then you should not really use stdio (that is C), and you should use cin and cout (with the >> and <<) operators for input and output).
    But all he needs to do is remove "#include <iostream>" and it becomes C.

  10. #10
    Join Date
    May 2008
    Location
    UK
    Beans
    1,451
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Homework help... Again.

    Arndt - very true - he needs to decide one way or another - or taught one way or another
    Tony - Happy to try to help.
    Unless otherwise stated - all code posted by me is untested. Remember to Mark the Thread as Solved.
    Ubuntu user number # 24044 Projects : TimeWarp - on the fly Backups

Page 1 of 3 123 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •