Like Tree1Likes
  • 1 Post By laserlight

Multiplication of odd or even integers according to user selection.

This is a discussion on Multiplication of odd or even integers according to user selection. within the C Programming forums, part of the General Programming Boards category; Greetings, I've been fighting with this program for some hours now, and there are so many things the program is ...

  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
    21,734
    You probably should be using a for loop. Note that keywords and names are case sensitive, so If and if are not the same.
    Click_here likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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,384
    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, 02:40 PM
  5. List Boxes - Detecting user selection
    By MrWizard in forum Windows Programming
    Replies: 5
    Last Post: 05-16-2002, 01:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21