The basics of programming in c++ for beginners

Tasks: arithmetic operations in C ++

If you have already read the articleArithmetic operations in C ++ you can begin to practice.

1. Common task:  Given the four-digit number (for example 5678), display the numbers in reverse order of which is the number of member. That is, we should see on the screen 8765. Tip: to take from among the individual numbers, should be applied to the modulo 10.

2. The site of almost any commercial bank, you can find the so-called Deposit calculator, which allows people to, not wishing to go into the formula for calculating interest rates, to know how much they will receive. To do this, they just fill in certain fields, press the button and see the result. This is a simple program, which has already been able to write each one of you. So, a task: The user enters the amount of the deposit and the number of months of keeping money in the bank. It is necessary to calculate and show the screen profit from the deposit in a month,  for the entire term of the deposit, and the total amount payable at the end of the period.  Currency let it be – U.S. dollar. Interest rate – 5% APR.  The formula for calculating percent per month–                      SumDeposit * (interest rate / 100)  / daysperyear * dayspermonths.

Perhaps you have any questions about the solution of tasks – ask them in the comments!

156 thoughts on “Tasks: arithmetic operations in C ++

  1. #include
    using namespace std;

    int main()
    {
    float deposit = 0;
    float numberOfMonth = 0;
    float profitOnMonth = 0;
    float profitForTime = 0;
    float fullAmount = 0;
    float interestRate = 5;
    cout << deposit;
    cout << numberOfMonth;

    profitOnMonth = deposit*(interestRate/100)/(365*30);
    profitForTime = profitOnMonth * numberOfMonth;
    fullAmount = deposit + profitForTime;

    cout << "Profit on month: " << profitOnMonth << endl;
    cout << "Profit for time: " << profitForTime << endl;
    cout << "Full amount: " << fullAmount;

    return 0;
    }

    Here is my code. I checked everything a thousand times. For the life of me, I don’t understand why the output is different from yours!!!! Recalculated on a calculator – the same!!! What did you do to receive such a response?????

    1. All your variables except interestRate are equal 0. And I don't see, so that you can enter them from the keyboard :)
      Or initialize them, or organize assignment during program execution.

    2. Spice it up


      #include
      using namespace std;

      int main()
      {
      float deposit = 1000;
      float numberOfMonth = 12;
      float profitOnMonth = 0;
      float profitForTime = 0;
      float fullAmount = 0;
      float interestRate = 5.0;

      profitOnMonth = deposit*(interestRate / 100) / 365 * 30;
      profitForTime = profitOnMonth * numberOfMonth;
      fullAmount = deposit + profitForTime;

      cout << "Profit on month: " << profitOnMonth << endl;
      cout << "Profit for time: " << profitForTime << endl;
      cout << "Full amount: " << fullAmount;
      system("pause");
      return 0;
      }

  2. P.S.
    cout deposit;
    cout numberOfMonth;
    It's not there. There's an error in the comment..
    Please explain why you get this answer.!

    1. that's where
      cout < < deposit; cout << numberOfMonth;
      do it
      cin >> deposit;
      cin >> numberOfMonth;

      and everything will work out

  3. It seems like a trifle, but it’s nice when there are results from a new interest)))
    Of my mistakes in this exercise, I’ll note:
    1) Inconvenient design (compared to the author);
    2) Didn't enter variables “number of days in a year” and “number of days in a month”, I just put them in the formula;
    3) Didn't assign values ​​to variables 0 at the very beginning – the program worked only when the calculation was a line above the output command on the screen

    1. Everyone makes enough mistakes while studying. In programming it’s even more so ) And not only during school.
      You can't get by with just one theory. – we need to solve more and analyze other people’s codes. Mine are far from ideal ;)

  4. Hi) For the first assignment I made this code:) Different from yours) I just can't understand how it works (my code) :D
    Prompt, you are welcome!)
    #include
    using namespace std;
    int main()
    {
    setlocale(LC_ALL, "rus");
    int four_digit_number;
    cout << four_digit_number;
    cout << "Число в обратном порядке: ";
    cout << four_digit_number % 10;
    cout << (four_digit_number / 10) % 10;
    cout << ((four_digit_number / 10) / 10) % 10;
    cout << (((four_digit_number / 10) / 10) / 10) % 10;
    getchar(); getchar();
    return 0;
    }

  5. Here is my code:

    #include
    using namespace std;

    int main()
    { double summa;
    double meciac;
    setlocale( LC_ALL,"Russian" );

    cout << "Введите сумму депозита" << summa;
    cout << "Прибыль с депозита в месяц" << summa*5/100/365*30 << endl;
    cout << "Введите количество месяцев" << meciac;
    cout << "Прибыль за весь срок депозита" << summa*5/100/365*meciac*30<< endl;
    cout << "Общая сумма к выплате за весь период" << summa + summa*5/100/365*meciac*30<< endl;
    system ("pause");
    return 0;
    }

  6. I have,along the way,the coolest code :DDDD

    setlocale(LC_ALL, "rus");

    double dol = 0;
    double month = 0;
    double prInMonth = 0;
    double alldep = 0;
    double allPr = 0;
    double interest = 5;
    int daysInMonth = 30;
    int daysInYear = 364;

    cout << "\t \t \\ Банк Егора,б***. \\ ";

    cout << endl << endl;

    cout <> dol;
    cout <> month;

    cout << endl << endl;

    cout << "\t \t Please,wait.We working :) \n";
    cout << "\t \t \\ ===================== \\ \n";

    cout << endl << endl;

    prInMonth = dol * (interest / 100) / daysInYear * daysInMonth;
    cout << "Your profit in month : " << prInMonth << endl;

    alldep = prInMonth * month;
    cout << "Your deposit for all your time : " << alldep << endl;

    allPr = dol + alldep;
    cout << "Your money for yout time : " << allPr << " usd " << endl;

    cout << endl << endl;

    _getch();
    return 0;

  7. My answer has zeros everywhere. Can you please tell me what is the error??

    int main()
    {
    setlocale(LC_ALL, "Russian");

    float sumDeposit = 0;
    int amountOfMounth = 0;
    int interestRate = 5;

    float profitForMounth = 0;
    float profitForYear = 0;
    float profitForAllRate = 0;

    int mounth = 30;
    int year = 365;

    cout <> sumDeposit;
    cout <> amountOfMounth;
    cout << endl;

    cout << "=============================" << endl;
    cout << "Происходит вычисление ...";
    cout << endl << endl;

    profitForMounth = sumDeposit*(interestRate/100)/(year*mounth);
    profitForYear = profitForMounth*amountOfMounth;
    profitForAllRate = profitForYear+sumDeposit;

    cout << "Прибыль с депозита за месяц: " << profitForMounth << endl;
    cout << "Прибыль с депозита за все время срока: " << profitForYear << endl;
    cout << "Общая сумма выплаты в конце срока депозита: " << profitForAllRate;

    _getch();
    return 0;
    }

    1. define not int interestRate = 5;
      а float interestRate = 5;
      the whole mistake is in this.
      When does the calculation start? (interestRate/100) – this is what happens: 5 divided by 100. it should work 0.05, but so how type defined int – the fractional part is discarded and remains 0.

      1. I have a stupid mistake, but still thank you very much for your help)

Leave a Reply

Your email address will not be published. Required fields are marked *