Thread: school project been killin me..

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    school project been killin me..

    alright.. been workin on this silly little program.. it's a numeric conversion program... here is what it needs to look like .. and i have to include while, if, and else if statements in it...

    2. The program should prompt the user as shown below:
    ---------------------------------------------------------------------
    NUMERIC CONVERSION PROGRAM
    ---------------------------------------------------------------------
    3. Enter Base of Input (d=decimal, o=octal, h=hexadecimal): d
    4. Enter Input Number: 178
    5. Enter Base of Output (d=decimal, o=octal, h=hexadecimal): h
    6. The integer 178 in decimal is equivalent to B2 in hexadecimal



    ---------------------------------------------------------------------------------

    and this is the pathetic crap i have so far... because i don't understand the if, while, and else if staments yet.. so any help would be greatly appreciated.. thank you in advance..

    ---------------------------------------------------------------------------------

    //
    #include
    int main (void)
    {
    int d, o, h, x;
    char base;

    long int D;
    long int O;
    long int H;


    printf("-----------------------------------------------------------------\n");
    printf(" NUMERIC CONVERSION PROGRAM \n");
    printf("-----------------------------------------------------------------\n");
    printf("Enter Base of Input (d=decimal, o=octal, h=hexadecimal) : ");
    scanf("%c", &base);
    printf("Enter input number : ");
    scanf("%d", &D, &O, &H);
    printf("Enter Base of Output (d=decimal, o=octal, h=hexadecimal) : ");
    scanf("%d", &D, &O, &H);
    if (base = h)
    printf("then your integer %d will be %h in hexadecimal:\n",D, D);
    return 0;
    if (base = o)
    printf("then your integer %d will be %o in octal:\n",D, D);
    return 0;
    if (base = d)
    printf("then your integer %d will be %d in decimal:\n",D, D);
    return 0;

    }
    //

    alright... i kinda started over, and am now only trying to get the program to return 1 type of conversion..... and i cannot get it to.. please help.. please tell me how far off i am.. lol


    /*
    #include <stdio.h>
    void main()
    {
    int D,O,H;
    int num;
    int d,o,h;


    char base;
    char base_out;


    printf("------------------------------------------------------\n");
    printf(" NUMERIC CONVERSION PROGRAM\n");
    printf("------------------------------------------------------\n");
    printf("Enter Base of Input (d=decimal, o=octal, h=hexadecimal) : ");
    scanf("%s", &base);
    printf("Enter input number : ");
    scanf("%d", &num);
    printf("Enter Base of Output (d=decimal, o=octal, h=hexadecimal) : ");
    scanf("%s", &base_out);
    if(base == d)
    {
    printf("then you integer %s would equal %d in decimal\n",base,base_out);
    }

    }
    */
    Last edited by oldsaintd; 03-19-2003 at 12:39 AM.

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    >>if (base = h)
    You're assigning for base the value of H, you need to use the == operator and not just = so, the correct is if (base == h);

    >>if (base = o)
    printf("then your integer %d will be %o in octal:\n",D, D);
    return 0;

    Again, use ==. When you want to execute a block, and not just a line of code, like in this case, you have to use bracets like here
    Code:
    if (base == o) {
        printf("then your integer %d will be %o in octal:\n",D, D); 
        return 0;
    }
    I don't get your idea here:
    Code:
    printf("Enter input number : ");
    scanf("%d", &D, &O, &H);
    printf("Enter Base of Output (d=decimal, o=octal, h=hexadecimal) : ");
    scanf("%d", &D, &O, &H);
    >>scanf("%d", &D, &O, &H);
    this is wrong, what you're trying to do? assign to these 3 variables the value of the input? if yes, try something like that:
    Code:
    scanf("%ld",&D);
    O = H = D;
    Also use code tags when posting in the forum, ahh welcome
    Last edited by Vber; 03-18-2003 at 03:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. Please, suggest a project ….
    By Dragon227Slayer in forum Tech Board
    Replies: 1
    Last Post: 06-12-2004, 10:48 AM
  3. I've been slacking off in high school, am I going to hell
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 06-01-2003, 01:00 PM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM
  5. Question about going to a technical school
    By Goalie35 in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:34 AM