What am I doing wrong?

I am learning c++. This is my first time to deal with struct's. This code will run correctly the 1st time. On the 2nd run, it automatically enters .00 for memeber bookno. It will prompt me every time to enter book.cost and book.sales as it should. I don't understand what I am doing wrong.


when I went to enter 2nd time, entered the book no and sales and it returned .00 3 201.6 (it did not let me enter cost). You can see from the output that it is not correct.


This is the data I would have wanted to enter:
1st run: bookno = 201.5. sales = 2 cost = 2.00
2nd: bookno: 201.6 sales= 3 cost = 3.00
3rd: bookno = 202 sales = 5 cost = 1.00
4th bookno = 207 sales = 6 cost = 5.00

Here is what I should be able to input:

201-5
2
2.00

201.6
3
3.00

202
5
1.00

207
6
5.00


This is all it would allow me to input and the out was screwed up.
input
201-5
2
2.00
output
201-5 2 2.00

input (this is where it screws up) - Please note: It would not allow me to enter the 3rd member.
201.6
3
****It did not let me enter my 3rd variable
output
.00 3 201.6

202
5
1.00

output
202 5 1.00

Screws up again: I would have liked to enter 207, 6, 5.00 instead this happens
207
6

output
.00 6 207


Thank you for anyone that can help!

#include <iostream>
using namespace std;

int main() {

struct sales_data
{
string bookno;
unsigned sales = 0;
double cost = 0;

};

sales_data book;


while ((cout << "enter Book data" << endl) && (cin >> book.bookno >> book.cost >> book.sales)){
cout << book.bookno << " " << book.sales << " " << book.cost << endl;

}

}


Last edited on
show your input
The problem has been fixed. I was entered data in the wrong order. I had sales and cost switched. I corrected this in my cin statement and the program worked correctly. Thank you for anyone who looked into this.
Topic archived. No new replies allowed.