0

Any problem with this code

#include <iostream> using namespace std; int main() { int a; int b=50; int c=a-b; int x=c-b; cin>>a; cout<<"the first bus took"<<b<<endl; cout<<"remaining in station"<<a-b<<endl; c=a-b; cout<<"second bus took"<<b<<endl; cout<<"now remaining"<<c-b<<endl; cout<<"last bus took all remaining"<<c-b<<endl; x=c-b; cout<<"a bus can trspt 50 at a time, now remaing seats"<<b-x<<endl; return 0; }

13th Jan 2021, 1:09 AM
Mubarak Hussain
Mubarak Hussain - avatar
3 Answers
+ 7
(1) You used the "a" before getting the input value so you have to first get the input by cin>>a; before using it. (2) "a-b" and "c-b" isn't necessary because you already have your "c" and "x" variable respectively And just additional, you can just do this: int x, y, z; instead of int x, int y, int z; https://code.sololearn.com/c0PRA9xeDVLy/?ref=app
13th Jan 2021, 1:34 AM
Nicko James Barata
Nicko James Barata - avatar
+ 2
I think you didn't initialize the variable a before using it: int a; int b=50; int c=a-b; The solution may be: int a; int b=50; int c; int x;
13th Jan 2021, 1:20 AM
Daniel Briceño
Daniel Briceño - avatar
13th Jan 2021, 1:41 AM
Mubarak Hussain
Mubarak Hussain - avatar