4 Replies - 2008 Views - Last Post: 25 November 2009 - 09:05 PM Rate Topic: -----

#1 ambererind  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 09

Dynamic Arrays

Posted 17 November 2009 - 11:50 AM

I am so confused here, I need to make a program that I have four computer labs.
Lab 1 has 1-5 stations
Lab 2 has 1-6 stations
Lab 3 has 1-4 stations
Lab 4 has 1-3 stations

I started it, but I don't think its right. Could someone please help me get it started and the middle part??? I am so confused on this and I'm getting really frustrated.. Any help would be greatly appreciated... Thank you very much.

- Amber


HERE IS WHAT I GOT SO FAR, but I don't think its right:

#include <iostream>
#include <new>
using namespace std;

int main ()
{
  int lab;
  int * lab1 * lab2 * lab3 * lab4;
  cout << "What station are you going to be on? ";
  cin >> i;
  lab= new int[i];
  if (lab == 0)
  else
  {
	for (lab=0; n<i; n++)
	{
	  cout << "Enter ID number: ";
	  cin >> lab[n];
	}
	cout << "You have entered: ";
	for (lab=0; n<i; n++)
	  cout << lab[n] << ", ";
	delete[] p;
  }
  return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Dynamic Arrays

#2 4D1  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 225
  • Joined: 22-October 09

Re: Dynamic Arrays

Posted 17 November 2009 - 12:17 PM

Hi Amber, your problem is you are declaring an integer of lab, and trying to create a dynamic array with that variable, you need to use one of your pointers instead.

I.e

int lab;
int * lab1 * lab2 * lab3 * lab4;

lab= new int[i];



Should be

int lab;
int * lab1 * lab2 * lab3 * lab4;//Dont know why you need 4 pointers, 1 would suffice

lab1= new int[i];



Also there is a way you can check that memory was successfully allocated.

int lab;
int  *lab1;

lab1= new (nothrow) int[i];

if(lab1[0]==0)
{
	 cout << "error Allocating memory";

}



Just in case you didnt know, when you ask "What station you are working at" the user input will create a dynamic array with space for as much as the user enters, is that what you want? If you try to explain your program more maybe I can help.

This post has been edited by 4D1: 17 November 2009 - 12:30 PM

Was This Post Helpful? 0
  • +
  • -

#3 ambererind  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 09

Re: Dynamic Arrays

Posted 24 November 2009 - 10:21 AM

Thank you D41, I Could still really use your help.. Thanks for taking the time out to help...

I need to write a program that could be used to track, by lab, which user is logged onto which computer? I need to add where I type a user id, in what station and which lab.. So people know who was using the computer on a station in a lab..

I don't understand why I'm not getting it, I can usually do this, but for some reason I'm not getting it...

Thank you, Amber
Was This Post Helpful? 0
  • +
  • -

#4 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 855
  • View blog
  • Posts: 2,338
  • Joined: 20-August 07

Re: Dynamic Arrays

Posted 24 November 2009 - 12:04 PM

View Postambererind, on 17 Nov, 2009 - 06:50 PM, said:

HERE IS WHAT I GOT SO FAR, but I don't think its right:

What do you mean by "don't think its right"? The way you need to do this is first by putting your code through a compiler and seeing what happens, then fix any errors which the compiler sees, then build your solution incrementally. I spot at least half a dozen separate compiler errors in the code you've pasted without even having tried to compile it

There's no point in me going any further, you need to make a serious attempt at writing something which you have at least tried to compile. When you've done this, and if you get stuck, come back and post the code you've tried and any errors you've encountered, or if your program runs and you believe isn't working as you intend, post a description of the problems you are having.
Was This Post Helpful? 0
  • +
  • -

#5 ambererind  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-September 09

Re: Dynamic Arrays

Posted 25 November 2009 - 09:05 PM

Bench,
I have compiled, thats why I came here to get help.. I am a beginner and get frustrated and kind of don't know EXACTLY what I'm doing!!!!!!! Thats why I said I didn't know what I was doing!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1