+ 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; }
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;
}
+ 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;
}
+ 3
Yeah, i understand it!!!🥳 thanks a lot🤝
+ 2
Did i have to inpunt “area” with length and width?
That is the one different i see, right?
0
How your code is wrong ??
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
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