C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++

You want to withdraw some money from your bank account. The program takes two numbers as input, your account balance and the amount you want to withdraw. Calculate and output the remaining balance after the withdrawal. Sample Input 450000 9000 Sample Output 441000 Anyone got a answer for this?

14th Sep 2021, 1:51 PM
Mando
Mando - avatar
5 Answers
+ 1
Use subtraction. If you follow the example you can see that 450000 - 9000 = 441000
14th Sep 2021, 1:56 PM
Brian
Brian - avatar
+ 1
Yes but it asks not only that equation, its just asking for a calculator that just does subtraction.
14th Sep 2021, 1:58 PM
Mando
Mando - avatar
+ 1
The next step in thinking about this is to understand that you would replace the literal numbers with variables. int a; int b; int c; a = 450000; b = 9000; c = a - b; then print c. cout << c; The final revision would be to get the values for a and b as input from the user instead of assigning literal values. cin >> a; cin >> b;
14th Sep 2021, 2:05 PM
Brian
Brian - avatar
0
Keep trying to make it work. That is the important part of the exercise. Figure out what went wrong. If there are error messages, read them. Review the lessons. If you still have trouble then show your code here and you will be able to get more help.
14th Sep 2021, 2:13 PM
Brian
Brian - avatar
0
#include <iostream> using namespace std; float subtract(float a, float b); int main() { float num1; float num2; float answer; //cout<< "Enter the first number:"; cin>>num1; //cout<< "Enter the seconde number:"; cin>>num2; answer = subtract(num1,num2); cout<< answer; return 0; } float subtract(float a, float b) { return a -b; }
14th Sep 2021, 4:21 PM
Sacalivin Obiri
Sacalivin Obiri - avatar