Thread: Multiplication of odd or even integers according to user selection.

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    5

    Multiplication of odd or even integers according to user selection.

    Greetings,

    I've been fighting with this program for some hours now, and there are so many things the program is requesting that I'm overwhelmed, I was wondering if anybody can point me in the right direction.

    I need a program that will calculate products based on user command (1 or 0), the user will select a number before this so that it can become the last number to be multiplied.

    If user inputs 0, calculate: 1*3*5*…*n (n is an odd number picked by the user)

    or 1*3*5*…*(n-1) (n is an even number picked by the user);

    If user input 1, calculate: 2*4*6*…*(n-1) (n is an odd number picked by the user)
    or 2*4*6*…*n (n is an even number picked by the user).

    So far I got...

    Code:
    #include<stdio.h>
    
    int main()
    {
        int n;
        int command;
        int result;
        int usernumber= 0;
    
    
        printf("Please input a positive integer:");
        scanf("%d", &n);
    
    
        printf("Please input the command for computation of products:");
        scanf("%d", &command );
    
    
        If (command == 1, usernumber++){
            do{
            printf( "%d", result);
            }
            while( nums > n )
        }
    
    
    }
    Please halp D:

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably should be using a for loop. Note that keywords and names are case sensitive, so If and if are not the same.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    5
    Good observation, I didn't even notice hehe. Thanks for your help, I'll keep working on this monster.

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    If you are still having trouble after you put in a 'for' loop, post your new code.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 03-26-2012, 10:50 AM
  2. Replies: 3
    Last Post: 11-01-2010, 08:22 PM
  3. Replies: 4
    Last Post: 07-24-2008, 09:02 AM
  4. element selection
    By Stinky in forum C Programming
    Replies: 2
    Last Post: 11-10-2003, 03:40 PM
  5. List Boxes - Detecting user selection
    By MrWizard in forum Windows Programming
    Replies: 5
    Last Post: 05-16-2002, 01:36 AM