Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 41
  1. #21

    na solve nani? hehehhee.

    you're too dependent to data structures if you use array, and yes, it can be achieved without using functions, medyo taas2x lng jud hinoon.
    id like to see your solution without using an array

    programming is all about data structures... at least that's what my teacher said.

    best solution ani.. sayo ka sud sa subject.. mangupya ka imo migo heehehehee.

    no need array4 and array5.
    yep sakto, i was thinking back then where to store them lol so i just call them array, pro an array that would keep
    hundres,thousand,million,billion would help.....
    Last edited by silent-kill; 08-31-2008 at 04:50 AM.

  2. #22
    Elite Member
    Join Date
    Aug 2008
    Gender
    Male
    Posts
    1,422
    Blog Entries
    1
    silent kill:
    #include<string.h>
    #include<conio.h>
    #include<stdio.h>
    char*getName(int num)
    {
    char word[25];
    switch (num)
    {
    case 1:strcpy(word,"one");break;
    case 2:strcpy(word,"two");break;
    case 3:strcpy(word,"three");break;
    case 4:strcpy(word,"four");break;
    case 5:strcpy(word,"five");break;
    case 6:strcpy(word,"six");break;
    case 7:strcpy(word,"seven");break;
    case 8:strcpy(word,"eight");break;
    case 9:strcpy(word,"nine");break;
    case 10:strcpy(word,"ten");break;
    case 11:strcpy(word,"eleven");break;
    .
    .
    .
    .
    .
    .
    case 65535:strcpy(word,"sixty five thousand five hundred thirty five");break;
    }
    return word;
    }
    void main()
    {
    int num=0;
    clrscr();
    scanf("%d",&num);
    printf(getName(num));
    getch();
    }

    this is my code.. my problem is how can i directly go to 65535 without following all of the numbers from 1-65535...

    mao na akong solution bai..pliss help me ASAP...

  3. #23
    onsa ka year college?
    ngano case 1-65535 man imo approach? heeheehehehe kani wai function para way libog

    ikaw na bahala convert to c++
    mao ni ako first og last nga tabang nimo goodluck

    val = input
    answer = output
    Code:
                string[] onesArray = {"zero", " one ", " two ", " three ", " four ", " five ", " six ", " seven ", " eight ", " nine " };
                string[] tensArray = {" ten "," twenty "," thirty "," forty "," fifty "," sixty "," seventy ", " eighty "," ninety "};
                string[] teens = { " ten "," eleven "," twelve "," thirteen "," fourteen "," fifteen ", " sixteen "," seventeen "," eighteen "," nineteen "};
                string answer = "";
                int tmpval;
                int divider = 1000;
                if (val > 99999)
                    return;
    
                while (divider > 1)
                {
                    if (val / 1000 >= 1)
                    {
                        tmpval = val / 1000;
                        if (tmpval >= 20) 
                        {
                            answer = tensArray[(tmpval / 10) - 1];
                            if (tmpval % 10 > 0)
                                answer += onesArray[tmpval % 10];
                        }
                        else if (tmpval >= 10 && tmpval <= 19) 
                            answer = teens[(tmpval - 10)];
                        else if (tmpval >= 1) 
                            answer = onesArray[tmpval];
                        divider = 1000;
                        val = val - (tmpval * 1000);
                        answer += " thousand ";
                    }
                    else if (val / 100 >= 1)
                    {
                        tmpval = val/100;
                        answer += onesArray[tmpval] + " hundred ";
                        divider = 100;
                        val = val - (tmpval * 100);
                    }
                    else if (val / 10 >= 1)
                    {
                        tmpval = val / 10;
                        if (tmpval >= 2)
                        {
                            answer += tensArray[tmpval - 1];
                            val = val - (tmpval * 10);
                        }
                        else
                        {
                            answer += teens[val - 10];
                            val = 0;
                        }
                        divider = 10;
                    }
                    else
                    {
                        if(val > 0)
                            answer += onesArray[val];
                        divider = 1;
                    }
                }

  4. #24
    Elite Member
    Join Date
    Aug 2008
    Posts
    1,053
    Blog Entries
    1
    Wow.... pass your assignment ^^ hehehhe

  5. #25
    Elite Member
    Join Date
    Aug 2008
    Gender
    Male
    Posts
    1,422
    Blog Entries
    1
    silent-kill:

    sori kaayo tol..mag lisod ko ug convert.dli ko kamao ug unsaon..1st year pa man gud ko...
    please help me...

  6. #26
    dali na mana bro nana gyud nai code ug concept

  7. #27
    wow... hatag na man apil codes

  8. #28
    6525

    6000 - six thousand
    500 - five hundred
    20 - twenty
    5 - five

    Just work it out..

  9. #29
    Elite Member
    Join Date
    Aug 2008
    Gender
    Male
    Posts
    1,422
    Blog Entries
    1
    problem solve..!!!!!!
    tnx a lot for the helps...
    ive learn something..

  10. #30
    this is done in Turbo C so conversion to C++ is not a problem anymore. As promised, this is just a partial solution to let bordogoy learn by example. This program accepts positive number from 1 - 99 only, if you provide a value which is lesser than 1 and greater than 99, it will ask for another number.s

    here is my solution, no arrays, no function, no fuss!

    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #define MAXSTR 80
    
    void main(){
    unsigned int input, ones, tens;
    char strout[MAXSTR], strone[MAXSTR], strten[MAXSTR];
    
      do{
        clrscr();
        printf("Enter a number from 1-99: ");
        scanf("%u",&input);
      }while((input<1)||(input>99));
    
      /*
        Get the TENS value and ONES value;
      */
    
       tens = input / 10;
       ones = input % 10;
     /* or ones = input - (tens * 10); */
    
       switch(tens){
         case 1: strcpy(strten,"Ten ");
             break;
         case 2: strcpy(strten,"Twenty ");
             break;
         case 3: strcpy(strten,"Thirty ");
             break;
         case 4: strcpy(strten,"Forty ");
             break;
         case 5: strcpy(strten,"Fifty ");
             break;
         case 6: strcpy(strten,"Sixty ");
             break;
         case 7: strcpy(strten,"Seventy ");
             break;
         case 8: strcpy(strten,"Eighty ");
             break;
         case 9: strcpy(strten,"Ninety ");
             break;
    
       }
       switch(ones) {
         case 1: strcpy(strone,"One ");
             break;
         case 2: strcpy(strone,"Two ");
             break;
         case 3: strcpy(strone,"Three ");
             break;
         case 4: strcpy(strone,"Four ");
             break;
         case 5: strcpy(strone,"Five ");
             break;
         case 6: strcpy(strone,"Six ");
             break;
         case 7: strcpy(strone,"Seven ");
             break;
         case 8: strcpy(strone,"Eight ");
             break;
         case 9: strcpy(strone,"Nine ");
             break;
       }
    
    
       strcpy(strout,strten);
       strcat(strout,strone);
    
    
       if(tens == 1){
       switch(ones) {
         case 1: strcpy(strout,"Eleven ");
             break;
         case 2: strcpy(strout,"Twelve ");
             break;
         case 3: strcpy(strout,"Thirteen ");
             break;
         case 4: strcpy(strout,"Fourteen ");
             break;
         case 5: strcpy(strout,"Fifteen ");
             break;
         case 6: strcpy(strout,"Sixteen ");
             break;
         case 7: strcpy(strout,"Seventeen ");
             break;
         case 8: strcpy(strout,"Eighteen ");
             break;
         case 9: strcpy(strout,"Nineteen ");
             break;
       }
      }
      printf("Value in String: %s\n",strout);
      getch();
    }
    I got to hand it to silent-kill, his code is much short and efficient, but for first year students who just had a first encounter with C based programming language, mangamote jud intawn kay dili jud kasabot. Mag.unsa manang ang code nga nga short and concise sa person nga dili pa ka comprehend sa logic of the program. It will be to complex for them.

    The best way to learn programming is to take it step by step, algorithm, flowcharting is the key. But if you have above average logic in programming you need not use algo/flowchart, just code it directly and debug as you go.

    I hope the thread starter learned from this experience, through the help of those who replied to this thread.
    Last edited by ChaosOrb; 09-01-2008 at 10:10 PM.

  11.    Advertisement

Page 3 of 5 FirstFirst 12345 LastLast

Similar Threads

 
  1. help me..!!!
    By hot_chick in forum "Love is..."
    Replies: 53
    Last Post: 07-13-2011, 03:21 PM
  2. Replies: 4
    Last Post: 12-26-2007, 02:03 PM
  3. Help me pangita sa PORK Barrel gihatag sa Goberno ngadtu....
    By dmcebu in forum Politics & Current Events
    Replies: 12
    Last Post: 06-06-2006, 02:02 PM
  4. Help Me I Cant Log In
    By mark eugene in forum Support Center
    Replies: 12
    Last Post: 06-06-2005, 02:35 PM
  5. hey help me
    By roselyn in forum Support Center
    Replies: 2
    Last Post: 04-23-2005, 04:59 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top