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.
Show code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intmainNumber=5678;
cout<<"Дано целое число: "<<mainNumber<<endl;
cout<<"Число наизнанку: ";
// остаток от деления четырехзначного числа 5678 на 10
cout<<mainNumber%10;// 5678 % 10 = 8
// далее делим mainNumber на 10 и записываем в переменную
// так как тип переменной int, дробная часть отбросится
// и mainNumber будет равен 567 (а не 567,8)
mainNumber/=10;
// показываем остаток от деления 567 на 10 на экран
cout<<mainNumber%10;
mainNumber/=10;
cout<<mainNumber%10;
mainNumber/=10;
cout<<mainNumber%10;
mainNumber/=10;
cout<<endl<<endl;
return0;
}
Result:
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.
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?????
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.
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
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 ;)
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; }
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; }
cout << "Прибыль с депозита за месяц: " << profitForMounth << endl; cout << "Прибыль с депозита за все время срока: " << profitForYear << endl; cout << "Общая сумма выплаты в конце срока депозита: " << profitForAllRate;
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.
#includeusing 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?????
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.
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;
}
P.S.
cout deposit;
cout numberOfMonth;
It's not there. There's an error in the comment..
Please explain why you get this answer.!
that's where
cout < < deposit; cout << numberOfMonth;do it
cin >> deposit;cin >> numberOfMonth;
and everything will work out
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
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 ;)
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!)
#includeusing 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;
}
pancake, not copied properly
Here is my code:
#includeusing 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;
}
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;
Soryan,but there is a little gram there. errors :D
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;
}
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.
I have a stupid mistake, but still thank you very much for your help)