- 1

Please what is wrong with this code. I used it to solve the transport task, but the app says it's wrong.

#include <iostream> using namespace std; using std::cin; int main() { //your code goes here int passengers; int seats; int emptyseats = seats - passengers; cout << "how many passengers" << endl; cin >> passengers; cout << "how many seats available" << endl; cin >> seats; cout << emptyseats << endl; return 0; }

4th Jul 2021, 6:24 PM
ibrahim agboola
ibrahim agboola - avatar
5 Respostas
+ 1
Where is your input statements you decleared two variables passengers amd seats you have not initialize them and trying operations on them . You applying operations on garbage values. And u used input statement at the last .
4th Jul 2021, 6:42 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
First write input statements then perform operations. And if u will print unnecessary strings then it will fail in test case becz u have to follow input akd output formats
4th Jul 2021, 6:50 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
A.S. Please how do I write it correctly
4th Jul 2021, 6:47 PM
ibrahim agboola
ibrahim agboola - avatar
0
A.S. Thanks, I have solved it.
4th Jul 2021, 6:57 PM
ibrahim agboola
ibrahim agboola - avatar
- 1
int main() { //your code goes here int passengers; int seats; cout << "how many passengers" << endl; cin >> passengers; cout << "how many seats available" << endl; cin >> seats; int emptyseats = seats - passengers; cout << emptyseats << endl; return 0; }
4th Jul 2021, 6:27 PM
Saket Bhatt
Saket Bhatt - avatar