cin

got a program cant use cin directly for numerics have to use like cin.getline but for some reason it does not work with the pointers i have set up please help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	#include <iostream>
	using std::cin;
	using std::cout;
	using std::endl;
	using std::ios;

	#include <iomanip>
	using std::setw;

	#include <cstring>
	#include <cstdlib>

	class course
	{
		public:
		char className[11]; // designation
		char term[7]; // Term
		int units; // Units
		char grade; // Grade
		course* next; // Next node
	};

	// Prototype(s)
	void printCourse(course*);
	int courseCmp(const course*, const course*);
	int myStricmp(const char*, const char*);
	int myStrnicmp(const char*, const char*, int count);
	
	int main()
	{
		
		char classEntry;
	
		// empty list
		course* head = 0;
		course* cEntry = 0;
	
		while(1)
		{
			// show list blank or already entered
			// Prompt user if they would like to enter another class
			printCourse(head);
			cout << endl;
			cout << "Would you like to enter another class? [Y/N]: "; 
			cin >> classEntry;
			cin.ignore(1000, 10);
			cout << endl;
		
			// if user enters no print class history and break
			if (classEntry == 'N' || classEntry == 'n')
			{
				printCourse(head);
				break;
			}

			// Otherwise enter all data
			if (classEntry == 'Y' || classEntry == 'y')
			{
				cEntry = new course;
				cout << "COURSE: Enter your course name [Ex: comsc-110, 10 Characters Max]: ";
				cin.getline(cEntry->className, 11);

				cout << "TERM: Enter the term [Ex: fa2011, 6 Characters Max]: ";
				cin.getline(cEntry->term, 7);

				cout << "UNITS: Enter # of units [1-5]: ";
				cin >> cEntry->units;
				cin.ignore(1000, 10);
Last edited on
cin.ignore(1000, 10);
Do not do that. Use cin.ignore(1000, '\n');
Windows line feed is actually two symbols: 10 and 13.
Aside from that code is working fine: everything working and cEntry is filled as it should.
Topic archived. No new replies allowed.