¡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.
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
+ 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 .
0
#include <iostream>
using namespace std;
int main() {
int s;
s = 900;
cin<< "450000";
cout<<"9000";
450000-s = 441000;
return 0;
}
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;
}
0
I can do this in python EZ:
a = int(input())
b = int(input())
print (a - b)