Thread: Simple program

  1. #1
    Registered User
    Join Date
    Nov 2010

    Simple program

    Hey guys just trying to write a simple program where I ask the user to in 2 number.
    So if the user puts the 8 first and then let say 2
    i print back the result 1 and 7,2 and 6,3 and 5,basically what ever adds up to 8
    So I have my printf and scanf wrote and variable stored and I'm the best way to do get my ansewr is to pass my variable to a function
    Something like int calculate(int total,int variations)
    but this is where I'm getting bogged down,like i have my total which is equal to 8
    but I dunno how to get my numbers equaling to it,maybe use an array or something or a bunch of if/else statements,I dunno

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posting your code would be much more easier for us to read than your post.

    From what I can gather, though I am probably mistaken, is that you are trying to write a program that takes 2 integer inputs, the first of which is the sum. The second number I believe is the amount of numbers that you want to add together to reach the sum?

  3. #3
    Registered User
    Join Date
    Nov 2010
    Ya your right in your assumption
    #include <stdio.h>
    #include <math.h>
    int total;
    int numbers;
    int calculate(x,y);
    int amount;
    int main()
    printf("Enter the total :\n");
    scanf("%i", &total);
    printf("Enter the number of combinations:\n");
    scanf("%i", &numbers);
    printf("The possible combinations for total are %i",amount);
    int calculate(x,y)
    My sample output would be
    Enter the total:
    Enter the number of combinations:

    The possible combinations for total are

    1 and 5
    2 and 4
    I'm going to limit my total allowed entered in staring off to be 9 and combinations 2 to make it easier starting and then increase them as I go on.
    Just with my is there an easy way to find the sum of a specific number or will I have to make a big massive array or something?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a very simple program
    By htdefiant in forum C++ Programming
    Replies: 13
    Last Post: 08-14-2007, 01:27 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  4. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM