5 Replies - 531 Views - Last Post: 14 August 2010 - 02:15 PM Rate Topic: -----

#1 sanrick06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-August 10

Need Help to with Initializing

Posted 13 August 2010 - 05:33 PM

Ok. Here's the problem I'm having. I'm dealing with Array (2D and Multidimensional Arrays). Now I know what I have to do but I don't I need help with initializing my funtctions. I understand the material, like I read it like 15 time already. The problem I'm having is that I don't really know how to initialize my function on my own. For instance, on the function getStudentCount()
I know what I need to do but I don't know how to incorporate the writing.
This is what I have so far...

#include<iostream>
#include<iomanip>
#define MAX_STUDENTS = 20

using namespace std;

int getStudentCount()
// Ask for and store the number of students from user
{
       cout<<"processing has started in getStudentCount()"<<endl;
       cout<<"Number of students in class; "<<endl;
       getStudentCount();
       return 0;
}

I know that I have to use something like this to store the number of students into an array.
ex. -- for (index = 0; index < 10; index++)
 cin >> list[index] = 0.0;



Is this correct.??? Now I think that I'm just overthinking this but could you just clear my head please..

Thank You..

Is This A Good Question/Topic? 0
  • +

Replies To: Need Help to with Initializing

#2 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: Need Help to with Initializing

Posted 13 August 2010 - 06:35 PM

hmmmm not sure what your trying to accomplish here.


What you have now is infinite recursion, which equals bad news bears

example
#include <iostream>

using namespace std;

//inside this you will do what you must!
int getStudentCount()
{
     cout<<"GetStudentCount has begun"<<endl;


     return 0; // return what you must here
}

int main()
{
     cout<<"Main has has begun"<<endl;
     getStudentCount();
     
     return 0;
}



Explain what your trying to do here

This post has been edited by ImaSexy: 13 August 2010 - 06:36 PM

Was This Post Helpful? 1
  • +
  • -

#3 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 284
  • View blog
  • Posts: 1,615
  • Joined: 15-May 08

Re: Need Help to with Initializing

Posted 13 August 2010 - 06:58 PM

Not exactly sure what you are trying to achive, however if you are simply wishing to show the MAX_STUDENTS then doing the following would suffice.

#include <iostream>
#include <iomanip>

#define MAX_STUDENTS 20

using namespace std;

int getStudentCount()	{	
	return MAX_STUDENTS;
}

int main() 
{
	cout << "Maximum Number of Students " << getStudentCount() << endl;
	return 0;
}



If this is not what you are after then let me know, not really sure what the aim of this is. If you wish to store students in a 2 dimensional array - then you might consider a class or struct to define students.

Edit* Forgot to mention the Infinite Recursion Issue. Cheers ImaSexy

:)

This post has been edited by DaneAU: 13 August 2010 - 07:00 PM

Was This Post Helpful? 1
  • +
  • -

#4 sanrick06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-August 10

Re: Need Help to with Initializing

Posted 13 August 2010 - 07:26 PM

Yea, this kinda helped..Just a brief description of what I'm trying to do. I'll include my program I have so far. It's kinda of a mess so.. I hope its readable.. Well I was trying to understand how to put the number of students ENTERED into my array. I din't want an answer just wanted an explanation so I could figured it out. So, from what I got in replies this what I came up with...

#include<iostream>
#include<iomanip>

#define MAX_STUDENTS = 20 					

using namespace std;




int getStudentCount()						// Ask for and store the number of students from user
{
	int numberStudents = getStudentsCount();

	cout<<"processing has started in getStudentCount()"<<endl;			
	cout<<"Enter number of students in class; "<<endl;
	cin >> getStudentsCount();
	for (numberStudents = 0; numberStudents < 20; numberStudents++)
		cin >> getStudentsCount[numberStudents];
	
	return 0;															
}


int getExamScores()													// Gets exam scores from user, loads the array
{
	cout<<"processing has started in getExamScores()"<<endl;			
	
	return;																
}	


int getLabScores()														// Gets lab scores from user, loads the array
{
	cout<<"processing has started in getLabScores()"<<endl;				
	return;																
}


int calculatePointGrades()												// Calculates the student's numeric grade, loads the point grade array
{					
	cout<<"processing has started in calculatePointGrades()"<<endl;		
	return;																
}


int calculateLetterGrades()											// Determines the student's letter grade, loads the array
{					
	cout<<"processing has started in calculateLetterGrades()"<<endl;	
	return;																 
} 


int showGradeData()													// Prints a table of the student's scores and grades from the arrays
{					
	cout<<"processing has started in showGradeData()"<<endl;			
	return;																
}


double intArrayAve()														// Averages the student's numeric exam grades from the array
{			
	cout<<"processing has started in intArrayAve()"<<endl;				
	return 0;															// returns average exam score to main
}


double doubleArrayAve()													// Averages the student's numeric lab grades from the array
{			
	cout<<"processing has started in doubleArrayAve()"<<endl;			
	return 0;															// returns average lab score to main
}



void main()														//Take to top after done with functions...		
{
	cout<<"processing has started in main()"<<endl;						
	 
	int numStudents = getStudentCount();
	
	getExamScores();
	getLabScores();
	calculatePointGrades();
	calculateLetterGrades();
	showGradeData();

	cout<<"processing has completed in main()"<<endl;					
	cin.ignore(2);
}

This post has been edited by sanrick06: 13 August 2010 - 07:36 PM

Was This Post Helpful? 0
  • +
  • -

#5 sanrick06  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 13-August 10

Re: Need Help to with Initializing

Posted 13 August 2010 - 07:35 PM

Now I'm just working one function at a time. So, right now I'm doing getStudentCount(). What I'm trying to do is input the entered number of students in an array. I don't exactly know how to. The code above is what I came up with..
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,396
  • Joined: 19-February 09

Re: Need Help to with Initializing

Posted 14 August 2010 - 02:15 PM

With getStudentCount() I would say you are just asking the user for the number of students they are going to enter. Which can be a number between 1 and MAX_STUDENTS.

In this function the user does not enter data into the array.

Within the function you need :-
a local variable to take the input from the user,
to get input from user,
to return the value from the function using the return statement.


In the main() function you have
int numStudents = getStudentCount();
which is fine.
You could test that the value is being returned, by printing out the value in numStudents.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1