Skip Navigation Links
C# Corner Home
Forum Home
Latest 50
Unanswered
Win Prizes
All Time Leaders
Jump to CategoryExpand Jump to Category
Login 
    Welcome Guest!
 Search Forum For :  
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName
   Home » C# Language » having a hard time with loops
       
Author Reply
john burns
posted 5 posts
since Feb 22, 2012 
from

having a hard time with loops

  Posted on: 22 Feb 2012       
Hello everyone
I tried to do this with if and else, didnt work.. im trying now with while(true) but im not sure whats the next step, please help me with the following console C# code


The process of finding the largest number (i.e., the maximum of a group of numbers) is used frequently in computer applications. For example, a program that determines the winner of a sales contest inputs the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. Write a C# program that uses a looping statement to determine and print the largest number of 10 numbers input by the user. Your program must use only three variables, as follows:
 counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed). number: The current number input to the program. largest: The largest number found so far.

Thanks!

Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: having a hard time with loops
  Posted on: 22 Feb 2012        0  
Alright John, it's an assignment and it is a pretty easy one. I am a student my self , my advice to you is to try your hardest and post your code here on forums, then we will be able to help you.  I did it for you, so you can have a general idea how to solve this problem. Also there's are different ways to solve this, such as using an array.

namespace ForumHelp
{
  class Program
  {
  static void Main(string[] args)
  {
  int counter=0;  // assign variables
  double largest=0;
  double number=0;

  while (counter != 10)  // use while loop 10 times, once counter = 10 quit
  {
  counter++;
  Console.WriteLine("Please enter the sales amount: ");
  number = Convert.ToInt32(Console.ReadLine());

  if (largest < number) // find the largest number
  {
  largest = number;
 
  }
 
  }
  Console.WriteLine("Larget number is " + largest); // display the number
  Console.ReadLine();
  }
  }
}
Practice makes it perfect && All science is either computer programming or stamp collecting
john burns
posted  5 posts
since  Feb 22, 2012 
from 

 Re: having a hard time with loops
  Posted on: 23 Feb 2012        0  
I am trying, each time we get an assignment i go back to the basics and when i want to apply it i get stuck!
Thank you so much, appreciate it really
Prime b
posted  420 posts
since  Dec 12, 2011 
from 

 Re: having a hard time with loops
  Posted on: 23 Feb 2012        0  
Yeah I feel ya, I had same problems, I still have problems. Also when someone helped you click the checkbox to mark as thread as answered
Practice makes it perfect && All science is either computer programming or stamp collecting
       
Nevron Gauge for SharePoint
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Advertise with us
Current Version: 5.2011.3.12
 © 1999 - 2012  Mindcracker LLC. All Rights Reserved