Adding?

This is a discussion on Adding? within the C Programming forums, part of the General Programming Boards category; Hey I'm working on this program and the last thing I need to do is in case 3, adding how ...

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    11

    Adding?

    Hey I'm working on this program and the last thing I need to do is in case 3, adding how many investments would be made and how many donations would have been made. How do I do that?

    Code:
    int main(void)
    {
    
    
        int initial_balance=0, choice=0, donation=0, invest=0, fund=0, balance=0, total_donation, total_invest;
    
    
        printf("Welcome!\n");
        printf("\nWhat is the inital balance of the fund?\n");
        scanf("%d", &initial_balance);
         fund = initial_balance;
    
    
        printf("What would you like to do?\n");
        printf("\t1 - Make a donation\n");
        printf("\t2 - Make an investment\n");
        printf("\t3 - Print balance of fund\n");
        printf("\t4 - Quit\n");
        scanf("%d", &choice);
    
    
    
    
        while(choice != 4)
        {
            switch(choice) {
                case 1:
                    printf("How much would you like to donate?\n");
                    scanf("%d", &donation);
                    break;
                case 2:
                    printf("How much would you like to invest?\n");
                    scanf("%d", &invest);
                    if (invest > donation)
                    printf("You cannot make an investment larger than the funds.\n");
                    fund = invest - initial_balance;
                    break;
                case 3:
                    balance=initial_balance+donation-invest;
                    printf("\nThe current balance of the fund is $%.2d.\n", balance);
                    total_donation = donation;
                    total_invest = invest;
                    printf("There have been %.l donations and %.l investments.\n", total_donation,total_invest);
    
    
                    break;
    
    
    
    
                default:
                printf("You made an invalid selection.\n");
            break;
    
    
            }//end switch
    
    
        printf("What would you like to do?\n");
        printf("\t1 - Make a donation\n");
        printf("\t2 - Make an investment\n");
        printf("\t3 - Print balance of fund\n");
        printf("\t4 - Quit\n");
        scanf("%d", &choice);
    
    
    
    
        }//end while

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Can you provide an example of how case 3 should be working? I mean, what is the input? The output?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    11
    Heres what a sample run should be...

    Welcome!
    What is the initial balance of the fund?
    15000

    What would you like to do?
    1 - Make a donation
    2 - Make an investment
    3 - Print balance of fund
    4 - Quit
    1

    How much would you like to donate?
    1000

    What would you like to do?
    1 - Make a donation
    2 - Make an investment
    3 - Print balance of fund
    4 - Quit
    2

    How much would you like to invest?
    2000
    You cannot make an investment of that amount.

    What would you like to do?
    1 - Make a donation
    2 - Make an investment
    3 - Print balance of fund
    4 - Quit
    2

    How much would you like to invest?
    500

    What would you like to do?
    1 - Make a donation
    2 - Make an investment
    3 - Print balance of fund
    4 - Quit
    3

    The current balance is $15500.00.
    There have been 1 donations and 1 investments. <~~~ This is where I'm not sure as how to get.



  4. #4
    Ultraviolence Connoisseur
    Join Date
    Mar 2004
    Posts
    520
    Investments take money away? Why can't you invest larger then the amount you donated? This is very strange, please provide the complete ruleset.

    Or do "investments" mean that you're removing money from the fund? (that sort of appears to be the intent?)

  5. #5
    Registered User
    Join Date
    Sep 2013
    Posts
    11
    Yes you are correct about the investments. These are the what the option choices are.

    Option 1:
    Prompt the user for their donation amount. Add this amount to the balance of the fund.

    Option 2:
    Prompt the user for their investment amount. In order to continue to provide scholarships, the fund cannot be allowed to fall below its initial amount. If an investment would bring the fund below that value, then simply print out “You cannot make an investment of that amount.” If the amount is valid, deduct it from the balance of the fund.

    Option 3:
    Print the current balance of the fund, the current total number of donations, and the current total number of investments.

    After options 1, 2, and 3 prompt the user with the menu again.

    Option 4:
    Print the final balance of the fund, the final total number of donations, and the final total number of investments.

  6. #6
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    something like
    Code:
    int number_of_donations_made = 0
    
    ...
    
    case 3:
       number_of_donations_made++;
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. adding to a set
    By Suchy in forum C++ Programming
    Replies: 4
    Last Post: 11-28-2006, 12:53 AM
  2. Adding!
    By Legacycx in forum C# Programming
    Replies: 2
    Last Post: 02-17-2005, 04:12 PM
  3. adding a VB gui
    By DMaxJ in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2003, 09:35 AM
  4. adding to C++
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 01-06-2003, 01:02 PM
  5. VS .NET .lib adding
    By (TNT) in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-24-2002, 05:43 PM

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