C++ | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 3

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 My attempt is in comments.

6th Sep 2021, 2:09 PM
Mando
Mando - avatar
5 Respuestas
+ 5
Read the task carefully. You need to take two inputs and calculate the remaining balance. It means if your inputs are a & b, output should be a-b You can go through this lesson to learn about taking inputs and output https://www.sololearn.com/learn/CPlusPlus/1607
6th Sep 2021, 2:31 PM
Simba
Simba - avatar
+ 1
You should learn a bit theory before write code. int account_balance=450000; int withdraw = 9000; int res = account_balance - withdraw; cout<<res<<endl; You have put a cout instead of cin, when you saved a value in a variable, you can print the number with cout<< and then the name of the variable. Everything you put in " " is a string, not an integer .
6th Sep 2021, 2:35 PM
Gigi
0
#include <iostream> using namespace std; int main() { int s; s = 900; cin<< "450000"; cout<<"9000"; 450000-s = 441000; return 0; }
6th Sep 2021, 2:09 PM
Mando
Mando - avatar
0
//My answer in C++: #include <iostream> using namespace std; int main() { double a = 9000.0; //resources availoble on your account double b = 500.0; // money youwant to withdraw cout << "Please enter amount of money you want to withdraw!" << endl; cin >> b; double diff = a - b; cout << endl; cout << endl << "You have withdriven: " << b << " €" << endl << "New resources available on account: " << diff << " €" ; return 0; }
8th Sep 2021, 10:35 AM
TeaserCode
0
I can do this in python EZ: a = int(input()) b = int(input()) print (a - b)
21st Jan 2022, 1:25 PM
Conor Walsh
Conor Walsh - avatar