Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,709 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,274 people online right now. Registration is fast and FREE... Join Now!




function multiple

 
Reply to this topicStart new topic

function multiple, function multiple

biddy
2 Feb, 2007 - 10:37 AM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2007
Posts: 12


My Contributions
hi guys

I am trying to write a program that uses a function multiple to determine for a pair of integers whether the second integer is a multiple of the first. The function should return 1 (true) if its the case or 0(flase). The funtion should be used in a prgram that inputs a series of pairs of integers.

I know my attempt is wrong, can anyone help
Thanks



#include <stdafx.h>
#include <stdio.h>

/* function main begins programme execution */
int main( void )
{
int counter = 1 ; /* declares and initializes counter */
int multipe = 0 ; /*declares and initializes multipe */
int number ; /* declares number */
int secnumber = 0 ; /* declares and initializes second number */

/* processing phase */
while ( counter <= 2 ) { /* loop 2 times */
printf( " Enter number : " ) ; /* prompt for input */
scanf( "%d", &number ) ; /* read number from user */

if (secnumber * secnumber == number) { /* begin loop to determine the if secnumber is a multiple of first number */

Printf( " True ") ;
else
printf( " False" );
} /* end if */


++counter / *increment counter */
} /* end while


return 0 ; /* indicate that program ended successfully */

} /* end function main */

User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Function Multiple
2 Feb, 2007 - 10:50 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,349



Thanked: 51 times
Dream Kudos: 25
My Contributions
First and foremost, you are not ever taking in a second separate variable. You are simply overwriting the first. I would suggest prompting the user for two different numbers using two different variables.
User is online!Profile CardPM
+Quote Post

biddy
RE: Function Multiple
2 Feb, 2007 - 10:56 AM
Post #3

New D.I.C Head
*

Joined: 26 Jan, 2007
Posts: 12


My Contributions
QUOTE(Amadeus @ 2 Feb, 2007 - 11:50 AM) *

First and foremost, you are not ever taking in a second separate variable. You are simply overwriting the first. I would suggest prompting the user for two different numbers using two different variables.


User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Function Multiple
5 Feb, 2007 - 09:51 PM
Post #4

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,153



Thanked: 44 times
Dream Kudos: 125
My Contributions
QUOTE(biddy @ 2 Feb, 2007 - 11:37 AM) *

I am trying to write a program that uses a function multiple to determine for a pair of integers whether the second integer is a multiple of the first. The function should return 1 (true) if its the case or 0(flase). The funtion should be used in a prgram that inputs a series of pairs of integers.



If I am not wrong then you are saying that you need to find whether second number is multiple of first.
This mean :
if
number 1 = 12 and
number 2 = 48 then

number 2 is multiple of number1 as 12 X 4 = 48. am I right? sleepy.gif

If yes then...

as Amadeus said first take numbers in 2 different variables.

then just do number2 % number1. [checking reminder]
If it's 0 then number2 is multiple of number1
else it is not.

And for series of pairs you can call this function in loop, right?

Hope this will help you. smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:25AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month