### Several integers at one place

Hi,
I am a complete beginner, i stumbled upon the following exercise but i am having difficulties solving it.
It is pretty basic, in one file solve the following in and outputs:

This is my code:
 ``1234567891011121314151617181920212223242526`` ``````#include using namespace std; // int main() { { int heltal; cout << "write whole number:"; cin >> heltal; cout << "you wrote:"<< heltal << endl; } { int a,b,c,d,e; cout << "write in five whole numbers:"; cin >> a >> b >> c >> d >> e; cout <<"you wrote:"<< a "\t" << b "\t" << c "\t" << d "\t" << e "\t" << endl; } { int a1; float flyttal; cout << "write in a whole number and decimal number:"; cin >> a1 >> flyttal; cout << "whole number is:" << a1 << "\n"; // cout << "decimal is :" << flyttal << endl; } return 0; }``````

Runexample 1is required and i have have no problems with it except of rounding the decimal... what is require is to be 3.1416, but when i run it it gets to 3.14159:
Write whole number: 10
You wrote: 10
Write in 5 whole numbers: 12 30 27 13 11
You wrote: 12 30 27 13 11
Write in a whole number and a decimal: 67 3.141592
You wrote whole number: 67
You wrote decimal: 3.1416

Runexample 2 is to test the code even further: when I type in 10.2 the program continues to execute the other lines without prompting for input, the otput code is below.
And this is what it should look like:
Write whole number: 10.2
You wrote: 10
Write in 5 whole numbers: -12 10330 27 13 11 five
You wrote: -12 10330 27 13 11
Write in a whole number and a decimal: 3267 3.141592 d
You wrote whole number: 3267
You wrote decimal: 3.1416

 ```Write whole number:10.2 You wrote:10 Write in 5 whole numbers:You wrote:0-716758921199580386122937002293512 Write in a whole number and a decimal: You wrote whole number::2293456 You wrote decimal:5.88796e-039 ```

Thanks in advance for any assistance
Last edited on
For Runexample1, float can store only 5 decimal places, whiles double stores 7. That is why it rounds up.

For Runexample2, int cannot store decimal values that is why it does that...but...I heard some people say badbit. I have not actually inspected it yet!

LOL?!?
Topic archived. No new replies allowed.