4 Replies - 1298 Views - Last Post: 19 September 2011 - 04:59 PM Rate Topic: -----

#1 megatron250  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-September 11

Errors with cin.get command. (Data Structure)

Posted 18 September 2011 - 01:42 AM

Hello,
I am trying to learn a bit more about structures, and would like to see if I could get some help. I am getting errors with the cin.get command, and I was wondering why. I did manage to figure out I have been having this problem with the int data within the structure. The way I have it right now, there is a red "squiggly" underneath the decimal between cin and the get. You probably will not know what I am talking about until you paste it into your own compiler. Does this mean I am missing something? Any help would be appreciated.

// auto_structure.cpp : Defines the entry point for the console application.
// 2011, September 16th.
// Stacy Douglas


#include "stdafx.h"
#include "iostream"
#include "iomanip"
#include "conio.h"
#include "string.h"

using namespace std;


 void main()
{//----------------------STRUCTURE. Comments in parenthesis are used as examples.
	struct autos{
	char make[20];  //Vehicular make. (Chevrolet)
	char model[20];  //Vehicular Model. (Camaro)
	int year[4];  //Year of production. (2011)
	char used;  //Is the vehicle used? (N)
	unsigned long kilometers[8];  //How many kilometers? (000,025)
	unsigned long cost[9];  // What is the cost? ($48,000)
	char p_windows;  //Does it have power windows? (Y)
	char p_locks;  //Does it have power locks? (Y)
	char secure;  //Does it have a security system? (Y)
	int capacity;  //How many people does it seat? (5)
	}autos[999];

	//Get the data from the user.

	int n = 0;

	for(int n = 0;n<999;n++)
	{
		cout << "Enter Vehicle Make" << '\n';
		cin.get(autos[n].make, 20);
		cin.ignore(80, '\n');

		cout << "Enter Vehicle Model" << '\n';
		cin.get(autos[n].model, 20);
		cin.ignore(80, '\n');

		cout << "Enter Vehicle Year" << '\n';
		cin.get (autos[n].year, 4);                   //Error line here. Under the "." in cin.get.
		cin.ignore(80, '\n');

		cout << "Is the Vehicle Used? (Y/N)" << '\n';
		cin.get(autos[n].used);
		cin.ignore(80, '\n');

		cout << "How many kilometers?" << '\n';       //Error line here. Same as above.
		cin.get (autos[n].kilometers, 8);
		cin.ignore(80, '\n');

		cout << "Cost of vehicle" << '\n';            //Error line here. Same as top.
		cin.get (autos[n].cost, 9);
		cin.ignore(80, '\n');
	
		cout << "Does it have Powered Windows? (Y/N)" << '\n';
		cin.get(autos[n].p_windows);
		cin.ignore(80, '\n');

		cout << "Does it have Powered Locks? (Y/N)" << '\n';
		cin.get(autos[n].p_locks);
		cin.ignore(80, '\n');

		cout << "Does it have an integrated security system? (Y/N)" << '\n';
		cin.get(autos[n].secure);
		cin.ignore(80, '\n');

		cout << "How many people can the vehicle accomodate?" << '\n';
		cin.get (autos[n].capacity, 1);                           //Error here too.
		cin.ignore(80, '\n');

	}
	
	//Relays previously entered data back to the user.

	for(n = 0;n < 999;n++)
	{
		cout << "Make: " << autos[n].make << '\n';
		cout << "Model: " << autos[n].model << '\n';
		cout << "Year: " << autos[n].year << '\n';
		cout << "Used?: " << autos[n].used << '\n';
		cout << "Kilometers: " << autos[n].kilometers << '\n';
		cout << "Cost: " << autos[n].cost << '\n';
		cout << "Powered Windows?: " << autos[n].p_windows << '\n';
		cout << "Powered Locks?: " << autos[n].p_locks << '\n';
		cout << "Security System?: " << autos[n].secure << '\n';
		cout << "Capacity: " << autos[n].capacity << " People." << '\n';
		cout << '\n';
	}
	_getch();
}



Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Errors with cin.get command. (Data Structure)

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: Errors with cin.get command. (Data Structure)

Posted 18 September 2011 - 01:50 AM

#include "iostream"

This is incorrect. It should be:
#include <iostream>
The same goes for iomanip, conio.h and string.h.
Was This Post Helpful? 1
  • +
  • -

#3 megatron250  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-September 11

Re: Errors with cin.get command. (Data Structure)

Posted 18 September 2011 - 03:46 AM

View PostPlasticineGuy, on 18 September 2011 - 01:50 AM, said:

#include "iostream"

This is incorrect. It should be:
#include <iostream>
The same goes for iomanip, conio.h and string.h.


I put the <...> around iostream, iomanip, conio.h, and string.h like you suggested, but unfortunately, I am still getting the errors. Any other suggestions?
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4237
  • View blog
  • Posts: 13,305
  • Joined: 25-December 09

Re: Errors with cin.get command. (Data Structure)

Posted 18 September 2011 - 05:52 AM

You can not use the get() member function to retrieve non character data. I would suggest that you use the stream extraction operator>> and getline() instead of get().

Also main() must be defined to return an int (int main()) and main should return an integer to the operating system.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 megatron250  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 18-September 11

Re: Errors with cin.get command. (Data Structure)

Posted 19 September 2011 - 04:59 PM

Hey everyone! I actually figured it out. I'm not using the int(s) for any math at the moment, so I simply made them char(s) and they worked perfectly! Thanks anyway to those who replied! Much appreciated. I'll definitely return to this forum when I need help with C++!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1