Jump to content
IGNORED

Learning C and


1magus

Recommended Posts

//Tyler Weiss

#include <stdio.h>

 

//Fuel SCAN PROGRAM

void main(void)

{

float distance, gallons, MPG;

 

printf("Enter distance followed by space than gallons used. \n");

scanf("%f %f", &distance, &gallons);

MPG = "%f / %f", &distance, &gallons;

printf("Fuel Effiency is: %f\n", MPG);

}

My teacher told us to make a program that calculates the fuel effeicny in Gallons and Liters and I know this is wrong lol but I can't get this to work :( and I do not have the liters area yet :( any help anybody?

Link to comment
Share on other sites

  • 2 weeks later...
MPG = "%f / %f", &distance, &gallons;

 

Like Karri said, you have tried to use the syntax of the scanf function to do math.

 

C = A / B; // division

C = A % B; // mod

C = A * B; // multiplication

C = A + B; // addition

C = A - B; // subtraction

 

that's the basic math syntax in C... you could probably ask your teacher for help, that's what he's there for!

 

Oh, I've always considered it good programming style to put in a "return;" even when the function doesn't return anything. Is that not taught today, or am I just plain wrong on that?

Edited by Shawn Jefferson
Link to comment
Share on other sites

  • 3 months later...
Oh, I've always considered it good programming style to put in a "return;" even when the function doesn't return anything. Is that not taught today, or am I just plain wrong on that?

I don't know I would consider that good programming style. That is a redundant statement, which doesn't aide readability IMO, so I would leave it out.

--Selgus

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...