product of an integer and a fraction

Hi there,

I am trying to make a simple program that will calculate 25% of 480.

When I put the code in using num1 as 480 and num2 as .25 it calculate a number of 0 for the product.

What is the trick to this? what am i doing wrong?

this is the code i am using:


#include <stdio.h>

int main(){
/*declare variables for each integer */
int num1, num2, product;
num1 = 480;
num2 = .25;
product = num1 * num2;
printf("25 percent of $%d is $%d.\n",num1, product);


you don't want to use integers.
assigning 0.25 to an integer will make that integer be equal to zero.
so what do I define it as? @mutexe
doubles? floats?
i'll be sure to look those up. i'm posting in the beginners post because obviously i'm a beginner... this is the first programming I've ever done. its for my intro course at university....so thank u
no worries dude.
have a read of the first section of this: http://www.cplusplus.com/doc/tutorial/
it should all become clear.
Topic archived. No new replies allowed.