d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Basic C Prototypes Help > Basic Prototypes
Add Reply New Topic New Poll
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Mar 12 2013 05:35pm
I need help building proto types for dividing, comparing, and an ATM menu that receives no paramaters, also building function definitions and function calls for each

here's one I have completed as an example unless you see an error yourself
Code
//- A function that divides two numbers and returns the remainder
#include <stdlib.h>
#include <stdio.h>
int imodulus(int, int); // function prototype

main ()
{
    int num1;
    int num2;
   
    printf("\nEnter the first number: ");
    scanf("%d", &num1);
    printf("\nEnter the second number: ");
    scanf("%d", &num2);
    printf("\nThe result is %d\n", imodulus(num1, num2));
    system ("pause");
}
// function definition
int imodulus(int num1, int num2)
{
   return num1 / num2;
}


here is what I have for comparing two large numbers
Code
//- A function that finds the larger of two numbers and returns the result
#include <stdlib.h>
#include <stdio.h>
int CompareTwoNumbers(int,int); // function prototype

main ()
{
    int num1;
    int num2;
   
    printf("\nEnter the first number: ");
    scanf("%d", &num1);
    printf("\nEnter the second number: ");
    scanf("%d", &num2);
    system ("pause");
}

//function definition
int CompareTwoNumbers (int num1, int num2)
{
return    if (num1 < num2)
             printf ("\n%d is less than%d\n", num1, num2);
             else if (num1 == num2)
             printf ("n%d is equal to %d\n", num1, num2);
             else
             printf ("\n%d is greater than %d\n", num1, num2);
}


and here is that I have for the ATM menu
Code
//- A function that prints an ATM menu—it receives no
//parameters and returns no value

void pMenu(void);

void pMenu();
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 13 2013 12:43am
you just created the prototypes, what is your problem you are having?
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Mar 13 2013 06:24pm
they need to have a function call, as in use in actual programming where they are used and operating the comparing one isnt even finished and wont run at all and thats the one im stuck on i havent tried p menu let alone used it
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 13 2013 08:00pm
Quote (Xarai @ Mar 13 2013 08:24pm)
they need to have a function call, as in use in actual programming where they are used and operating the comparing one isnt even finished and wont run at all and thats the one im stuck on i havent tried p menu let alone used it


your compare two numbers looks right but remove the return keyword and set the function to void. its useless to return anything if all you want to do is send output to stdout.

whats not working about your code. "wont run at all" doesnt give any one here much to go on... next time you post please put some thought into it and try to describe what is happening. maybe even supply where the code is breaking.

This post was edited by AbDuCt on Mar 13 2013 08:01pm
Member
Posts: 23,261
Joined: Dec 17 2006
Gold: 18,129.00
Mar 14 2013 01:39pm
Does this need to be done dynamically in classes or in one file? Obviously, classes are better but it depends where you are at in school or whatever. It seems like you're pretty basic. Wrote this up for you. It's far from optimal or flawless, but it should give you a good idea of what you need to do from here. Sorry, I can't do c# syntax quickly as I don't know it well, but you should be able to see what I'm doing anyhow.

Code
int display_menu(); // displays menu and returns the selection
int compare(int, int); // compares 2 numbers and returns the larger
int divide(int, int, &int, &int);  // divides and returns remainder

int main()
{
int menu_answer, num1, num2, quotient, remainder;
display_menu();

if(menu_answer = 1)
{
 compare(num1, num2);
}
else
{
 divide(num1, num2, quotient, remainder)
}

return 0;
}

int display_menu()
{
int menu_answer;
cout << "Please pick an option by typing in the number" << endl;
cout << "1.  Compare 2 numbers" << endl;
cout << "2.  Divide 2 numbers" << endl;

return menu_answer;
}

int compare(num1, num2)
{
if( num1 < num2)
 return num1;
else
 return num2;
}

int divide(num1, num2, quotient, remainder)
{
int i = num1;
int quotient=0;
if (num1 > num2)
{
 while((i - num2) > quotient)
 {
  i = i - num2;  
  quotient++;
 }

 remainder = i;
}
else
{
 while((i - num1) > quotient)
 {
  i = i - num1;
  quotient++;
 }
 remainder = i;
}
}

Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Mar 14 2013 02:18pm
thanx ownage
abduct might have gone about helping in a rude way but he did somewhat help

here is my finished product and it works correctly as intended


Code
//- A function that finds the larger of two numbers and returns the result
#include <stdlib.h>
#include <stdio.h>
int CompareTwoNumbers(int,int); // function prototype

main ()
{
    int num1;
    int num2;
   
    printf("\nEnter the first number: ");
    scanf("%d", &num1);
    printf("\nEnter the second number: ");
    scanf("%d", &num2);
   
}

//function definition
 int CompareTwoNumbers (int num1, int num2)
{
    if (num1 < num2);
                printf ("\n%d is less than %d\n", num1, num2);
                else if (num1 == num2)
                printf ("\n%d is equal to %d\n", num1, num2);
                else
                printf ("\n%d is greater than %d\n", num1, num2);
                system ("pause");
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll