Welcome to Dream.In.Code
Become a C# Expert!

Join 150,392 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,060 people online right now. Registration is fast and FREE... Join Now!




For and While Loop with students

 
Reply to this topicStart new topic

For and While Loop with students, making a program that does all kinds of jazz with students and classes

jamespierre
3 Mar, 2008 - 10:26 AM
Post #1

New D.I.C Head
*

Joined: 3 Mar, 2008
Posts: 7

I had another example in class today making a program that calculates some stuff about students and classes and what not. the teacher still is not the greatest at explaining loops because i still dont get it but for compare and contrast sakes, using a for and a while loop, how can i do the same task? any ideas? i need help on the "code here" parts


A user will input the integer number of students in 5 different classes. Validate the number of students is in the range of 1 to 28. Include in the prompt the class number. Calculate the lowest number of students, the highest number of students and average number of students for the 5 classes. Include in the output that class number for each statistical result. The double average number of students must be displayed with two decimals.

Sample Prompt:

Number of students in Class #1:

Sample Output:

Class #1 had the lowest number of students



CODE
using System;
using System.Collections.Generic;
using System.Text;

namespace Lab3ConsoleMTT2
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < maxNumClasses; i++)
{

// code here

}



for (int i = 0; i < classArray.length; i++)
{

// code here

}



int currentClass = 0;

while (currentClass < maxNumClasses)
{

// code here

currentClass++;

}



int currentClass = 0;

while (currentClass < classArray.Length)
{

// code here

currentClass++;

}



int currentClass = 0;

do
{

// code here

currentClass++;

} while (currentClass < maxNumClasses);
}
}
}

User is offlineProfile CardPM
+Quote Post

zakary
RE: For And While Loop With Students
3 Mar, 2008 - 10:37 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
ok so a for loop will loop or repeat the code for a given number of times. so


csharp

// this is i is 0; loop until i is 10 or greator; add 1 to i
//for each time it loops.
for (int i=0; i<10; i++)
{
// code here
}


now a while loop to do the same


csharp

// this is while n is less than 10 repeat code
int n = 0;

while (n < 10)
{
//code here
n++; // add 1 to n
}


This post has been edited by PsychoCoder: 3 Mar, 2008 - 05:56 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month