please help me to correct/ build/ complete the program

J

jyck91

#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
 
O

osmium

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>
 
M

mark_bluemel

#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.
 
N

Nick Keighley

#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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top