• 0

Newbie C help (I know its not C++ or C#)


Question

Hello guys!

 

So I'm writing this program that takes 2 integers and determines if the first number is an integer multiple of the second number.  I'm using the % operator.  I'm also trying to determine if the second number is an integer multiple of the first number.  So far this is what I have:

#include "stdio.h"

int x, y;

void main()

{
	printf("Please enter in the first whole number\n");
	scanf("%d", &x);
	printf("Please enter in the second whole number\n");
	scanf("%d", &y);

	if ((x % y) == 0)
		printf("The number %d is a multiple of %d\n",x,y);
	if ((y % x) == 0)
		printf("The number %d is a multiple of %d\n",y,x);

}

So far I have gotten the program to run almost flawlessly until it comes to the 2nd if statement.  I cannot get this silly program to work correctly.  It tells me that the 1st number is a multiple of the 2nd number, but it will not tell me if the 2nd number is a multiple of the first.  Any ideas?  Any and all help will be greatly appreciated!

 

Tera

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0
it will not tell me if the 2nd number is a multiple of the first.

 

Sample run:

 

Please enter in the first whole number
1
Please enter in the second whole number
2
The number 2 is a multiple of 1

 

The program tells you that the 2nd number is a multiple of the first as specified. What's wrong with it?

Link to comment
Share on other sites

  • 0

Sample run:

 

 

 

The program tells you that the 2nd number is a multiple of the first as specified. What's wrong with it?

I need it to also tell me if the first number is a multiple of the second.  I know it is redundant....

Link to comment
Share on other sites

  • 0

I need it to also tell me if the first number is a multiple of the second.  I know it is redundant....

Your program only tells you that a number is a multiple of the other if it is. It cannot currently tell you that a number is not a multiple of another. You need a printf somewhere with "The number x is not a multiple...".

Link to comment
Share on other sites

  • 0

OH!    Sheesh, I feel silly now.  Thank you so much for pointing out the obvious to me lol.  Just feel free to call me Captain Oblivious =)

We all do silly stuff like this, don't worry about it :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.