O.k My teacher game me a take home exam which will be submitted on monday..... and also I have to defend what I composed so I will ask you many questions so that I will understand this program..... my teacher said Never use C... do it in your own ideas....

Problem 1: Write a program to read in a distance expressed in kilometers and output the distance expressed in miles. One kilometer is equal to 0.62137 miles.
Example Ouput:
Enter Value in Kilometers:4
Value in Mile: 2.48548

Here is my program:

#include<stdio.h>
main()
{
int a;
float b=0.62137,c;
printf("Enter Value in Kilometers:");
scanf("%d",&a);
c=a*b;
printf("Value in miles:%f",c);
getch();
return 0;
}

Is this right???

no looping at all - just one multiplication needed.
what have you tried?

Problem 2: Write a progam that accepts an integer input representing the total number of seconds and outputs the equivalent time in hours and minutes.
Example Output:
Enter total number of seconds:5400
Equivalent in hours:1.5hr
Equivalent in minutes:90min

Here is my program:

#include<stdio.h>
main()
{
int a;
float b=60.0,c=60.0,d,e;
printf("Enter total number of seconds:");
scanf("%d",&a);
d=a/b; // In Minutes
e=d/c; // In Hours
printf("Equivalent in hours:%f",e);
printf("Equivalent in minutes:%f",d);
}

Is This correct???

Kilometer should be float as well.

Ok, here are some hints.

Problem #1:

1 - main must return an int, so write

int main()

instead of just

main()

2 - try to give more meaningful names to your variables (i.e. km instead of a, kmToMiles instead of b, miles instead of c)
3 - remove getch() - if you read the output of your second program then you don't need it
4 - as it's written the program will work, only it will just accept integer values for km input - it's up to you to decide if this is right or wrong.

Problem #2

1 - same as problem # 1
2 - same as problem # 1
3 - b and c are exactly the same - why bother and keep two variables?

Apart from these both programs will "work". Just let me suggest you to not open generic threads with misleading titles in which to iterately post your questions. Try to open a thread for every problem for which you need help (you didn't much so far).

Last thing:

my teacher said Never use C... do it in your own ideas....

doesn't make sense to me. Does it make to you? If so please clarify, it could be a requirement that I didn't care of.

ok thanks i'll rearrange and print it thanks for the advices.... plus my teacher just give us something that we could do without the help of c in the lab... since usually when someone is done they would just open the file and copy it.... Even so when my teacher said delete before he checked it there is still a way for them to cheat so he gave us this.... And it usually is fair to me... then when were done with the paper work he'd let us write our work in c and try to defend it in our own words.... Thanks again... ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.