please help me to correct/ build/ complete the program

Discussion in 'C Programming' started by jyck91@gmail.com, Mar 21, 2007.

  1. Guest

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    main()
    {
    float num;
    int i, temp, remainder, baseM, j;
    printf("Enter a number:");
    scanf("%f",&num);
    printf("Enter the base that you want:");
    scanf("%d",&j);
    if (temp > baseM){
    temp = num;
    remainder = temp % baseM;
    temp = temp / baseM;
    }
    for ( i=num; i>=0; i++)
    remainder = remainder;
    printf("%s",remainder);
    system("PAUSE");
    }

    ****** this is a base conversion program(part 2)
    I want to convert the base10 number to baseM( first in 2-9)
    eg. 5(10)------>101(2)
    eg. 10(10)-----> 22(4)
    ******the above program can not run and there are some mistake that i
    can't find out
    please help me to correct them

    ******Since i need to hand in it tomorrow , please help me as soon as
    possible
    thank you for your help
    , Mar 21, 2007
    #1
    1. Advertising

  2. osmium Guest

    <> wrote:

    No fix. Just some observations.

    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <string.h>
    > #include <math.h>
    > main()
    > {
    > float num;
    > int i, temp, remainder, baseM, j;
    > printf("Enter a number:");
    > scanf("%f",&num);


    Why don't you get a program that works just for positive integeres first?
    You can do the floating thing later.


    > printf("Enter the base that you want:");
    > scanf("%d",&j);
    > if (temp > baseM){


    temp has an unknown value, but you use it in a comparison. Why do that?

    <snip>
    osmium, Mar 21, 2007
    #2
    1. Advertising

  3. Guest

    On 21 Mar, 13:23, wrote:
    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <string.h>
    > #include <math.h>
    > main()
    > {
    > float num;
    > int i, temp, remainder, baseM, j;
    > printf("Enter a number:");
    > scanf("%f",&num);


    1) scanf is generally not a good idea for a beginner.
    2) why are you trying to work with a float?
    3) In addition you haven't flushed output, or finished your prompts
    with newlines, so there's no guarantee they'll be seen.

    > printf("Enter the base that you want:");
    > scanf("%d",&j);
    > if (temp > baseM){


    neither temp nor baseM have been assigned values

    > temp = num;
    > remainder = temp % baseM;
    > temp = temp / baseM;
    > }
    > for ( i=num; i>=0; i++)
    > remainder = remainder;


    remainder is not an array

    > printf("%s",remainder);
    > system("PAUSE");
    >
    > }
    >
    > ****** this is a base conversion program(part 2)
    > I want to convert the base10 number to baseM( first in 2-9)
    > eg. 5(10)------>101(2)
    > eg. 10(10)-----> 22(4)
    > ******the above program can not run and there are some mistake that i
    > can't find out
    > please help me to correct them
    >
    > ******Since i need to hand in it tomorrow , please help me as soon as
    > possible
    > thank you for your help


    We will not provide you with a complete solution, and there is so much
    wrong with the code you've put up here that there's frankly little
    chance of getting it into any useful state.

    If you can't do the task set, you need to go back and talk to your
    instructor.
    , Mar 21, 2007
    #3
  4. wrote:

    > #include <stdio.h>
    > #include <stdlib.h>
    > #include <string.h>
    > #include <math.h>
    > main()


    int main (void)

    > {
    > float num;
    > int i, temp, remainder, baseM, j;
    > printf("Enter a number:");


    fflush(stdout);

    > scanf("%f",&num);
    > printf("Enter the base that you want:");
    > scanf("%d",&j);
    > if (temp > baseM){
    > temp = num;
    > remainder = temp % baseM;
    > temp = temp / baseM;
    > }
    > for ( i=num; i>=0; i++)


    this won't terminate if i starts off > 0

    > remainder = remainder;
    > printf("%s",remainder);
    > system("PAUSE");


    return 0;

    > }
    >
    > ****** this is a base conversion program(part 2)
    > I want to convert the base10 number to baseM( first in 2-9)
    > eg. 5(10)------>101(2)
    > eg. 10(10)-----> 22(4)
    > ******the above program can not run and there are some mistake that i


    what does "can not run" mean?


    > can't find out
    > please help me to correct them
    >
    > ******Since i need to hand in it tomorrow


    perhaps you should have started sooner?

    > , please help me as soon as
    > possible
    > thank you for your help



    --
    Nick Keighley
    Nick Keighley, Mar 22, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joon
    Replies:
    1
    Views:
    515
    Roedy Green
    Jul 8, 2003
  2. KK
    Replies:
    2
    Views:
    545
    Big Brian
    Oct 14, 2003
  3. John Dalberg
    Replies:
    1
    Views:
    366
    Greg9Strat
    Mar 9, 2007
  4. Replies:
    4
    Views:
    353
    osmium
    Oct 19, 2008
  5. Replies:
    0
    Views:
    92
Loading...

Share This Page