As a complete beginner I am truing to solve some examples that I stumble upon in books and tutorials, this one is givin me headaches for several days:
This is my code:
#include <iostream> using namespace std; // int main() int a,b,c,d,e; float flyttal; cout << "write whole number:"; cin >> a; cout << "you wrote:"<< a << endl; 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; cout << "write in a whole number and decimal number:"; cin >> a >> flyttal; cout << "whole number is:" << a << "\n"; // cout << "decimal is :" << flyttal << endl; return 0; }
For this assignment there are 2 RUN requirements
Runexample1- works fine with no problems
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 (how do I round this number)
Runexample2 - after I type in the decimal number in the whole number field it works fine up until "you wrote 10" and then the program executes the rest of the line without prompting for "cin".
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
This is the code that I get after i type in 10.2 .. the program continues without stopping for "cin"
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

New Topic/Question
Reply



MultiQuote






|