can anyone help newbie in c programming

This is a discussion on can anyone help newbie in c programming within the C Programming forums, part of the General Programming Boards category; can anyone leave a clue on how to convert number to word using switch case statement i can only make ...

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    4

    can anyone help newbie in c programming

    can anyone leave a clue on how to convert number to word using switch case statement i can only make 1-10 number to word i just need a clue how to make hundreds to thousands thx!!!

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,655
    Show us what you've done thus far and maybe we can help.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,655
    For those that don't want to download unformatted code:
    Code:
    #include<stdio.h>
    main()
    {
        int x;
        clrscr();
        printf("\n input any number to convert: ");
        scanf("%d",&x);
        switch (x)
        {
            case 0:printf("Zero");break;
            case 1:printf("one");break;
            case 2:printf("two");break;
            case 3:printf("three");break;
            case 4:printf("four");break;
            case 5:printf("five");break;
            case 6:printf("six");break;
            case 7:printf("seven");break;
            case 8:printf("eight");break;
            case 9:printf("nine");break;
            case 10:printf("ten");break;
            case 11:printf("hundred");break;
        }
        printf("\n");
        getch();
    }

  4. #4
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    how can i post it like that??hehehe

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    4
    Code:
    #include<stdio.h>
    main()
    {
    int x;
    clrscr();
    printf("\n input any number to convert: ");
    scanf("%d",&x);
    switch (x)
    {
    case 0:printf("Zero");break;
    case 1:printf("one");break;
    case 2:printf("two");break;
    case 3:printf("three");break;
    case 4:printf("four");break;
    case 5:printf("five");break;
    case 6:printf("six");break;
    case 7:printf("seven");break;
    case 8:printf("eight");break;
    case 9:printf("nine");break;
    case 10:printf("ten");break;
    case 11:printf("hundred");break;
    }
    printf("\n");
    getch();
    }
    can anyone give me clue on how to make hundreds thousands number to word conversion

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Click on the # icon in the advanced reply window (at the top header). Put the cursor right between the [CODE] tags it will give you. Then paste your code into that area between the code tags.

    The forum code looks best if you have your editor use spaces (2-5) for indentation, instead of commas.

    This is what just two spaces indentation looks like (my preference):

    Code:
    for(i=0;i<NumberToBeSorted-1; i++) {
      for(j=i+1;j<NumberToBeSorted;j++) {
        if(matrix[i] > matrix[j]) {
          temp = matrix[i];
          matrix[i] = matrix[j];
          matrix[j] = temp;
        }
      }
    }

  7. #7
    Registered User shrikanth's Avatar
    Join Date
    Aug 2010
    Location
    Banglore, India
    Posts
    5

    Smile Number to word

    Quote Originally Posted by tears04 View Post
    can anyone leave a clue on how to convert number to word using switch case statement i can only make 1-10 number to word i just need a clue how to make hundreds to thousands thx!!!
    well this is very simple, i hav done it till 999, u can make necessary modifications for 1000 and bigger nos..

    Code:
    #include <stdio.h>
    
     int main()
     {
       int n=0,digits=0,m=0;
       clrscr();
       printf("enter the no\n");
       scanf("%d",&n);
       m=n;
       if(m==0)
       printf("Zero");
    
        while(m!=0)
        {
          digits++;
          m=m/10;
        }
    
       if(digits==3)
        {
          digits--;
          m=n-(n%100);
          n=n%100;
           switch(m)
    	{
    	  case 100: printf("one hundred ");   break;
    	  case 200: printf("two hundred ");   break;
    	  case 300: printf("three hundred "); break;
    	  case 400: printf("four hundred ");  break;
    	  case 500: printf("five hundred ");  break;
    	  case 600: printf("six hundred ");   break;
    	  case 700: printf("seven hundred "); break;
    	  case 800: printf("eight hundred "); break;
    	  case 900: printf("nine hundred ");  break;
    	}
        }
    
    
        if(digits==2)
         {
           digits--;
    
           if(n>=10 && n<20)
    	 {
    	  digits=0;
    	  switch(n)
    	   {
    	    case 10: printf("ten");      break;
    	    case 11: printf("eleven");   break;
    	    case 12: printf("twelve");   break;
    	    case 13: printf("thirteen"); break;
    	    case 14: printf("fourteen"); break;
    	    case 15: printf("fifteen");  break;
    	    case 16: printf("sixteen");  break;
    	    case 17: printf("seventeen");break;
    	    case 18: printf("eithteen"); break;
    	    case 19: printf("nineteen"); break;
    	   }
    	 }
    
    	else
    	 {
    	  m=n-(n%10);
    	  n=n%10;
    	   switch(m)
    	   {
    	    case 20: printf("twenty ");   break;
    	    case 30: printf("thirty ");   break;
    	    case 40: printf("fourty ");   break;
    	    case 50: printf("fifty ");    break;
    	    case 60: printf("sixty ");    break;
    	    case 70: printf("seventy ");  break;
    	    case 80: printf("eighty ");   break;
    	    case 90: printf("ninety ");   break;
    	   }
    	}
         }
    
        if(digits==1)
         {
           switch(n)
    	{
    	  case 1: printf("one");  break;
    	  case 2: printf("two");  break;
    	  case 3: printf("three");break;
    	  case 4: printf("four"); break;
    	  case 5: printf("five"); break;
    	  case 6: printf("six");  break;
    	  case 7: printf("seven");break;
    	  case 8: printf("eight");break;
    	  case 9: printf("nine"); break;
    	}
        }
    
        getch();
        return 0;
    }
    Last edited by shrikanth; 08-11-2010 at 02:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 07:46 AM
  2. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 07:49 PM
  3. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  4. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 02:17 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 03:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21