b0ng01's Profile User Rating: -----

Reputation: 38 Craftsman
Group:
Contributors
Active Posts:
170 (0.16 per day)
Joined:
16-July 10
Profile Views:
2,915
Last Active:
User is offline Jun 21 2012 07:54 AM
Currently:
Offline

Previous Fields

Dream Kudos:
50
Icon   b0ng01 dumb bug of the day: void setValue(int d)(d=this.d;)

Posts I've Made

  1. In Topic: Convert number symbols to words

    Posted 20 Jun 2012

    	else if (number >= 20 && number < 100) //2 digit numbers, > 20
    	{
    
        int n =  (number / 10) % 10; // pulls off the tens place
        n -= 2;
    
    		cout <<  greaterThan19[n] << endl;//lessThan20[secondNum]<< " dollar";
    
        int secNum = (number % 10 ); // saves the ones digit into secNum
        cout << secNum << endl;
            cout << lessThan20[secNum ] << endl;
    
    

    You need to do what is done with n and secNum for the Hundreds and Thousands as well. I don't think it is a great idea to index into an array with the number you pulled from input but, it will work if you pay attention to how you setup your array. ie... notice I subtracted 2 from n.
  2. In Topic: Learning C++: Make switch 'default' loop to beginning of switc

    Posted 19 Jul 2011

    There are multiple ways to do what you want.

    Here are two: First with a function through recursion and then with just a loop

    Through function with recursion:
    void checkOption(int num)
    {
    
        switch(num)
        {
            case 1:
            cout << "Option 1" << endl;
            break;
            case 2:
            cout << "Option 2" << endl;
            break;
            case 3:
            cout << "Option 3"  << endl;
            break;
            default:
            cout << "Illegal option: please input valid 1-3" << endl;
            int value;
            cin >> value;
            checkOption(value);
            break;
    
        }
    
    }
    
    int main()
    {
    
    checkOption(4);
    
    
        return 0;
    }
    
    


    Through loop:
    int main()
    {
    
    //checkOption(4);
    
    bool reloop = true;
    int num = 0;
    while(reloop)
    {
        cout << "Enter option 1-3" << endl;
     cin >> num;
    
        switch(num)
        {
            case 1:
            cout << "Option 1" << endl;
            reloop = false;
            break;
            case 2:
            reloop = false;
            cout << "Option 2" << endl;
            break;
            case 3:
            reloop = false;
            cout << "Option 3"  << endl;
            break;
            default:
            cout << "Illegal option: please input valid 1-3" << endl;
            int value;
    
            break;
    
        }
    
    }
    
        return 0;
    }
    
    
  3. In Topic: Using an int (or other) variable ina text string?

    Posted 19 Jul 2011

    dblpost
  4. In Topic: Using an int (or other) variable ina text string?

    Posted 19 Jul 2011

    YOu use the insertion operator << just like you would for regular text. example

    int age = 6;
    cout << "At age " << age << "you are old as dirt" << endl;
    
    
    


    prints: "At age 6 you are old as dirt"


    It works the exact same way for a file.
  5. In Topic: fgets getting skipped

    Posted 19 Jul 2011

    Because you were using it on an integer. I couldn't even get your code to compile until I changed buf to a char. http://www.cplusplus...y/cstdio/fgets/ There is no int for that first parameter. I don't think it was your scanf that was causing the problem it was your fget. You don't actually need the scanf's.

    
    


    int main()
    {



    int port1, port2;

    char buf[100];
    char secBuf[100];

    char roomname1[100];
    char roomname2[100];

    printf("Please enter the name of chatroom 1 : ");

    fgets(roomname1,100,stdin);

    printf("Please enter the port of chatroom 1 : ");

    fgets(buf,100,stdin);

    // sscanf(buf,"%d",&port1);



    // fflush(stdin);



    printf("Please enter the name of chatroom 2 : ");

    fgets(roomname2,100,stdin);
    // string stophere;
    // cin >> stophere;
    cout << roomname2 << endl;
    printf("Please enter the port of chatroom 2 : ");

    fgets(secBuf,100,stdin);
    cout << secBuf << endl;
    // sscanf(secBuf,"%d",&port2);


    return 0;
    }

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

Comments

Page 1 of 1
  1. Photo

    k1ngcor3y Icon

    12 Sep 2010 - 09:44
    I didn't know you were on codelearners too
Page 1 of 1