Help with +,-,* etc..

This is a discussion on Help with +,-,* etc.. within the C++ Programming forums, part of the General Programming Boards category; Hey dudes and dudettes I want to do a "mathematical program", i started out like this that i have underneath, ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    11

    Question Help with +,-,* etc..

    Hey dudes and dudettes

    I want to do a "mathematical program", i started out like this that i have underneath, and I want to end up the program by first doing an mathematical equation (which i can find out by myself) and present how many days it'll take for him to save up to that amount of money. The thing is, how do I continue with the code to do a multiplacation and division etc.. do u know what i mean?

    Thanks in advance,
    Micheal


    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    
    int salary,rent,lon;
    
    cout<< "How much do you want to save up too? ";
    cin>> lon;
    cout<< "\n";
    cout<< "How much do you put in your bank per month? ";
    cin>> salary;
    cout<< "\n";
    cout<< "What is the bank rent per year? ";
    cin>> rent;
    cout<< "\n";
    cout<< "You want to have "<< lon << " kronor" << " by putting in "<< salary << " kronor per month with a rent of " << rent << " percent per year.\n";
    
          system("PAUSE");
          return 0;
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Um, no I don't know what you mean. Like this?
    Code:
    int A = 3;
    int B = 5;
    std::cout << A << " * " << B << " = " << A * B << std::endl;
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    humm.. i mean, first the user is gonna give out his variables for salary, lon, rent ... then i want to multiply the salary with 12 (months) and multiply it with the RENT and then find out how many yrs it'll take for him to save up to that bit of amount he wants..

    Regards,
    Micheal

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    You basically do the code the same as you'd write the formula in your math class. Show us the formula to get the result and will help you convert that to C++ code
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    okay now yea I understand! Thanks for the help dudes! One more thing though, in which he writes in his "rent" it is meant to be in procentual form.. meaning if he types 2, then i will take it as 2% .. but mathemtically in C++ how do I add 2% of an certain sum? (IRL i need to do 'certain sum' multiply with 1,02)

    Best Regards,
    Micheal

  6. #6
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Code:
    float rent;
    
    cout << "Enter rent: ";
    cin >> rent;
    rent = rent / 100;
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    thanks dude alphaoide! can you tell me what float is?
    thankks again!!

  8. #8
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    float allows you to store numbers such as 1.00, 1.02, 10.5, 10.456
    int only store whole numbers as 1, 2 , 100
    Code:
    int num = 5;
    
    num = num / 2;   num is now "2" instead of the intended "2.5"
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    erm dude.. is this the right way to start the code with float and int

    Code:
    int main()
    {
    
    int salary,lon;
    float rent;
    cout<< "........

  10. #10
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    You mean the order you declare the variables? Doesn't matter.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  11. #11
    Registered User
    Join Date
    Nov 2003
    Posts
    11
    okay so far i've done this (underneath), now i just got to find a way so that it does the equation over and over again until the sum of it becomes the sum of the "lon" which is the sum he wanted from the beginning..did i confuse u as i confused myself? :P

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    
    int salary,lon;
    float rent;
    cout<< "How much do you want to save up too? ";
    cin>> lon;
    cout<< "\n";
    cout<< "How much do you put in your bank per month? ";
    cin>> salary;
    cout<< "\n";
    cout<< "What is the bank rent per year? ";
    cin>> rent;
    cout<< "\n";
    cout<< "You want to have "<< lon << " kronor" << " by putting in "<< salary << " kronor per month\nwith a rent of " << rent << " percent per year.\n\n";
    cout<< "In one year you'll have " << salary*12*(rent/100+1) << " kronor.\n";
    
    
          system("PAUSE");
          return 0;
    }

  12. #12
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    do u know how to construct a loop at all
    http://www.cprogramming.com/tutorial/lesson3.html
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

Popular pages Recent additions subscribe to a feed

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