Input needed on starting an assignment.

Hello,

I need assistance on starting writing my code, the direction states that the input will be taken from standard input, and so we need to define a book, the ISBN is 13 digit number. The title is a string of arbitrary length that ends with a line break.
B<ISBN><Title>
Ex. B 1231243556211 Title

I am fairly new to C++ and would like to get suggestion on how to start. Thanks!

Start it the same way you do with any other program. What do you think this program is going to need to do this job? How are your going to store the info you get? You are going to need variables for the for the different info. The ISBN is going to have to be able to hold 13 digits and I recommend using get line and to input the title as a string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
using namespace std;
int main()
{
string title;
int isbn = 0;
cout << "enter isbn" << endl:
cin >> isbn;
cin.ignore();
cout << "enter title" << endl;
getline (cin, title);


cout << isbn << endl << title;
cin.get ();
return 0;
}
Last edited on
@joe864863
Ah ok, I shall attempt that, and see what happens. Thanks.

@imohamme5
Thanks on your input, my code so far resembles that of yours, thus it seems I am heading in right direction.
At 13 digits, a valid ISB number will be too large to store in many platforms' int.

I suggest using a string, or a wrapper class around a single string. It will require some extra validation, but you gain portability.

Alternatively, make sure you ask for an integer that is large enough. A 64-bit integer is the most common big-enough type:
using isbn = std::uint_least64_t;
Last edited on
Topic archived. No new replies allowed.