why does not this code work? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

why does not this code work?

#include <iostream> using namespace std; int main(){ int line1, line2, mohi=(line1+line2)*2 ,masa=line1*line2; cout<<"enter the first side of rectangle: "<<endl; cin>>line1; cout<<"enter the second side of rectangle: "<<endl; cin>>line2; cout<<endl<<endl<<endl<<"masahat: "<<masa<<endl<<"mohit: "<<mohi; return 0; }

31st May 2023, 4:50 PM
Faran Allah Verdi
Faran Allah Verdi - avatar
1 Answer
+ 5
first assign values to variable then set the operations latter. try this: #include <iostream> using namespace std; int main(){ int line1, line2; cout<<"enter the first side of rectangle: "<<endl; cin>>line1; cout<<"enter the second side of rectangle: "<<endl; cin>>line2; int masa=line1*line2; int mohi=(line1+line2)*2 ; cout<<endl<<endl<<endl<<"masahat: "<<masa<<endl<<"mohit: "<<mohi; return 0; }
31st May 2023, 5:15 PM
Sultan Khalid
Sultan Khalid - avatar