+ 2

Need help! C++ basic arithmetic

Hello, I get the right answer 12.42 but my code is wrong. #include <iostream> using namespace std; int main() { double length= 5.4; double width= 2.3; //cin >> length; //cin >> width; double area = 5.4*2.3; cout <<area; return 0; }

21st Sep 2021, 10:29 AM
StefanFocht
StefanFocht - avatar
7 Respuestas
+ 3
You should take the inputs from the user, don't define yourself. So, your code must be, #include <iostream> using namespace std; int main() { double length; double width; cin >> length; cin >> width; double area = length*width; cout <<area; return 0; }
21st Sep 2021, 10:40 AM
mesarthim
mesarthim - avatar
+ 3
Sergfio I think you are trying to resolve a challenge which requires user input to create the values. Since this will be tested with hidden values, you must create a code with flexibility. Might I suggest you review the following code snippet to see if it helps. #include <iostream> using namespace std; int main() { double length, width, area; cin >> length; cin >> width; area = length * width; cout << area; return 0; }
21st Sep 2021, 11:32 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 3
Yeah, i understand it!!!🥳 thanks a lot🤝
21st Sep 2021, 12:05 PM
StefanFocht
StefanFocht - avatar
+ 2
Did i have to inpunt “area” with length and width? That is the one different i see, right?
21st Sep 2021, 12:04 PM
StefanFocht
StefanFocht - avatar
0
How your code is wrong ??
22nd Sep 2021, 7:03 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar
0
#include <iostream> using namespace std; int main() { double length; double width; cin >> length; cin >> width; double area = length*width; cout <<area; return 0; } i dont know why my code is not ruunning
6th Feb 2022, 12:20 PM
Noah Mugaya
Noah Mugaya - avatar
0
GOD OF CONFIG It works for me. Are you putting in your numbers on separate lines? PS: If you have a questiin, create a separate post on Q&A. Don't piggy-back off an existing post
6th Feb 2022, 9:32 PM
Rik Wittkopp
Rik Wittkopp - avatar