Sign in to follow this  
Followers 0
Terabojin

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

8 posts in this topic

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites
Terabojin, on 16 Sept 2013 - 21:09, said:

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

 

1 % 2 == 1 !

Share this post


Link to post
Share on other sites

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...".

Share this post


Link to post
Share on other sites

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 =)

Share this post


Link to post
Share on other sites

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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.