Hello tashmanm,
To the right of the code box there is a gear icon and the words "Edit & Run". Press the gear icon and it will put your code in a shell program.When you press the "Run" button it will compile and give the error messages that
Ganado is talking about.
Fix the first error and the second 2 will go away and give you a new error message.
For the last error message what it refers to is the use of the insertion operator (<<) when the "cin" needs the extraction operator (>>).
Except for the errors on lines 12 and 13 your code looks very good. The only suggestion I have is that line 2 does not need to be blank. Otherwise the use of blank lines is good.
With the line
cin >> a >> b;
it expects 2 variables and those entries are expected to be numbers. Entering anything other than a number will cause "cin" to fail and become unusable.
To expand on what
jlb said and I think what you are doing is: 10.25Enter puts the cursor on the next line waiting for you to enter the second number. This will work, but you do not get a prompt for the second number.
As the following code shows in the prompt and as
jlb said you can enter 10.25 20.5Enter.
This should work, but I can not test it until I post this. If I find a problem I will do an edit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
#include <iomanip>
using namespace std;
int main(void)
{
double a{};
double b{};
std::cout << std::fixed << std::showpoint << std::setprecision(2); // <---Added.
cout << "enter a and b (1.25 2.5): ";
cin >> a >> b;
std::cout << "\n\n You entered: " << a << " " << b << '\n';
return 0; // <--- Not required, but makes a good break point.
}
|
Other than line 14 that I added this should give you some ideas.
I initialized the variables when defined, not always necessary, but I like to know that they do not contain a garbage value. From C++11 on the uniform initializer, the {}s, makes it so easy it is just a good habit to get into.
Andy
Edit: Added line 11.
The output looks like this:
enter a and b (1.25 2.5): 10 20
You entered: 10.00 20.00
|