Looping exercise

C# Console application

Page 1 of 1

3 Replies - 3503 Views - Last Post: 09 October 2009 - 05:53 AM Rate Topic: -----

#1 sheztc77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-October 09

Looping exercise

Post icon  Posted 08 October 2009 - 03:10 AM

Hi,
I am very new to C#. I have just started a course which has a C# module. I was given a work sheet with a few different applications to make. I managed all but one. I simply can not figure out what kind of loop it should be and if there should be any if statements. The instructions for this application is as followed:

Write a program to read in a collection of exam scores ranging in value from 1 to 100. The input will
terminate with the value ‐1. As each score is input a category should be output: excellent 100 90;
good 89 70; satisfactory 69 50; unsatisfactory 49 1. After all the scores have been input the
program should then display the number of scores in each category.

Test your program with the following data: 6, 98, 76, 43, 87, 75, 24, 100, 96, 57, 68, 25, 89, 50, 29, 78, 2, -1.

I need to hand this in by Monday morning, but I am seriously struggling on what code and how to to structure it. Would really appreciate any help. This is all to be done in C# Express 2008 console application.
Thank you,
Shez :)

Is This A Good Question/Topic? 0
  • +

Replies To: Looping exercise

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Looping exercise

Posted 08 October 2009 - 04:01 AM

Well, this is how I'd go:

1. Initialize int variables for each category (these keep track of how many times a number belonging to that category has been written)
2. Start loop which is always true (while (true) {})
3. Ask for input
4. Parse the input as integer
5. Check in what category does the input fit and increase the appropriate variable declared in step 1. Also print out the word which describes the category.
6. If number is -1, use break; to get out of the loop. If it's not -1, let the loop continue.
7. Print how many numbers belongs to each category.

Or actually I wouldn't use while(true) as loop because it can be done without it but that was the easiest way to describe the flow.
Was This Post Helpful? 0
  • +
  • -

#3 liza12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 05-October 09

Re: Looping exercise

Posted 08 October 2009 - 05:07 AM

if the input is character how??
Was This Post Helpful? 0
  • +
  • -

#4 Searock  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 259
  • Joined: 15-September 09

Re: Looping exercise

Posted 09 October 2009 - 05:53 AM

View Postliza12, on 8 Oct, 2009 - 04:07 AM, said:

if the input is character how??


All you have to do is to declare a string variable.
Instead of checking for int variable in if statement you need to check for character

if(ch=="n")
{
	 break;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1