Jump to content

Recommended Posts

Posted

I have a very very basic C++ problem... Here's my code so far:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
/* Initiate Variables */
	int miles, gallons, mpg;

/* Get Vaules for Variables */
	printf("Enter miles driven: ");
	scanf_s ("%d", &miles);
	printf("Enter gallons used: ");
	scanf_s ("%d", &gallons);

/* Calculate MPG, then output */
	mpg = gallons / miles;
	printf("Your miles per gallon was: %d\n", mpg);


return 0;
}

But if ran, I get 0 unless miles = gallons, I get 1. It's doing a "trancauted 0?" or something.. Idk. I need help.. I forgot how to get this to run right.

Posted

I haven't done c++ in awhile, but I think because you have the values initiated as 'int' it won't display decimals. So, you have it set up to divide miles by gallons, which gives you less than 1, ergo it displays 0. So I would try switching it to mpg = miles / gallons and see what that gives you.

That should fix it.

Posted (edited)

Oh wow I am a DA... I don't even know how I typed those backwards.. Works like a charm now.

EDIT: O DAM MR BALL IS THAT U MY NIGGA? HALOMODS? DAT U?

Edited by TLEJ
Posted

BEEN 2 LONG. WERE TURAL @???

And yeah, I think that's why I ended up typing them backwards.. I originally had miles/gallons=mpg in my head, and I knew I had to switch them around, so I guess I switched everything..

Posted

Who knows. Probably off moderating and saying no pix no pruf on some forum somewhere.

Yeah, going from thought to keyboard changes sometimes. At least it's all working now.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Who's Online   0 Members (See full list)

    • There are no registered users currently online
×
×
  • Create New...