Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 2nd, 2006, 09:26 AM
westpointg westpointg is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 1 westpointg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 15 sec
Reputation Power: 0
Need Programming Help ASAP

Hey,
Im taking a programming class and this program has gotten me stuck
if anyone can help me please do
Write for loops that accomplish the following tasks:

1) Let the user input a String and an integer. Then use a for loop
to print the String that number of times.

Example:
Input a string: Hello
Input an integer: 3

Output: Hello Hello Hello


2) Let the user input an integer. Then use a for loop to sum the
even, odd and all of the numbers between 0 and the input number (inclusive).
HINTS: the input number could be negative.
you will need 3 sum variables to keep track of the different
sums.

Example:
Input an integer: 10
Sum of the even numbers from 10 to 10 = 30
Sum of the odd numbers from 0 to 10 = 25
Summ of all the numbers from 0 to 10 = 62

3) Let the user input a String and use a for loop to count the number
of vowels (a, e, i, o, u) & consonants in the String and print
the results.

Example:
Input a string: Hello
Number of vowels in Hello = 2
Number of consonants in Hello = 3

Reply With Quote
  #2  
Old November 6th, 2006, 12:46 AM
albertindian albertindian is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 165 albertindian User rank is Corporal (100 - 500 Reputation Level)albertindian User rank is Corporal (100 - 500 Reputation Level)albertindian User rank is Corporal (100 - 500 Reputation Level)albertindian User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 19 h 5 m 40 sec
Reputation Power: 4
Send a message via Yahoo to albertindian
Answer for first one
Code:
<%
strDataString=request.form.item("txtString")
strDatanoTimes=request.form.item("txttimes")

For lIntI=1 to strDatanoTimes
     response.write strDataString & " " 
Next
%>

Reply With Quote
  #3  
Old November 6th, 2006, 11:02 PM
David2006 David2006 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 1 David2006 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 27 sec
Reputation Power: 0
start a new C# Console application named Program.
Then insert this into Program.cs.
Be sure to test it, then convert it to ASP.

Good luck.

Code:

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

class Program
    {
        static void Main(string[] args)
        {

            Selector();
        }

        private static void Selector()
        {
            string sRepeat;
            string sFunction;
            Console.WriteLine("Choose a program");
            Console.WriteLine("1: String Repeater");
            Console.WriteLine("2: Sums");
            Console.WriteLine("3: Character Counter");

            sFunction = Console.ReadLine();

            switch (sFunction) {
                case "1": 
                    {
                        F1();
                        break;
                    }

                case "2":
                    {
                        F2();
                        break;
                    }
                case "3":
                    {
                        F3();
                        break;
                    }

            }

            Console.Write("\nWould you like to try again?[Y/N]");
            sRepeat = Console.ReadLine();
            if (sRepeat.ToLower() == "y")
            {
                Selector();
            } 

        }

        private static void F1()
        {
            //F1 - Repeat string
            //(no parameters)

            int iNumberOfWrites;
            string s;

            try
            {
                Console.WriteLine("String to repeat:");
                s = Console.ReadLine();
                Console.WriteLine("Number of times to print it:");
                iNumberOfWrites = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine("The following error occurred:\n{0}", e.Message);
                Console.WriteLine("Invalid Input.");
                return;
            }

            for (int j = 1; j <= iNumberOfWrites; j++)
            {
                Console.WriteLine(s);
            }
        }

        private static void F2()
        {
            //F2 - SumTotal, SumOdd, and SumEven
            //(no parameters)
            
            Int16 iNumberInput;
            long iSumTotal =0;
            long iSumEven =0;
            long iSumOdd=0;
            bool isOdd;

            try
            {
                Console.WriteLine("Enter your number:");
                iNumberInput = Convert.ToInt16(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid Input");
                return;
            }

            // Math works much better...
            iSumTotal = (iNumberInput+1) * iNumberInput / 2;
            iSumEven = Convert.ToInt32(Math.Pow(iNumberInput / 2, 2) + iNumberInput / 2);
            iSumOdd = Convert.ToInt32(Math.Pow((iNumberInput+1) / 2, 2));
            //Adjust for negative input
            iSumTotal = Math.Sign(iNumberInput) * iSumTotal;
            iSumOdd = Math.Sign(iNumberInput) * iSumOdd;
            iSumEven = Math.Sign(iNumberInput) * iSumEven;

            iSumTotal = 0;  //resetting because they're used below
            iSumOdd = 0;    //resetting because they're used below
            iSumEven = 0;   //resetting because they're used below
            //...but here goes the hard way.


            isOdd = true;
            for (int j = 1; j <= Math.Abs(iNumberInput); j++)
            {

                iSumTotal = iSumTotal + j;

                // start at 1, which is odd 
                iSumOdd = iSumOdd + j * Convert.ToInt32(isOdd);
                iSumEven = iSumEven + j * Convert.ToInt32(!isOdd);
                
                // flip boolean
                isOdd = !isOdd;
            }

            //Adjust for negative input
            iSumTotal = Math.Sign(iNumberInput) * iSumTotal;
            iSumOdd = Math.Sign(iNumberInput) * iSumOdd;
            iSumEven = Math.Sign(iNumberInput) * iSumEven;

            Console.WriteLine("Sum Total: {0}", iSumTotal);
            Console.WriteLine("Sum Even: {0}", iSumEven);
            Console.WriteLine("Sum Odd: {0}", iSumOdd);

        }

        private static void F3()
        {
            //F3 - Count Vowels and Consonants
            //(no parameters)
            int iNumVowels = 0;
            int iNumConsonants = 0;
            string s;

            try
            {
                Console.WriteLine("String to parse:");
                s = Console.ReadLine().Trim().ToLower();
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid Input.");
                return;
            }

            //Loops are not the easiest way...
            //iNumVowels = s.Split(new char[] { 'a','e','i','o','u' }).Length - 1;
            //iNumConsonants = s.Split(new char[] { 'b','c','d','f','g','h','j','k','l','m','n','p','q  ','r','s','t','v','w'}).Length - 1;
            //...but we'll use them anyway.
            for (int j = 0; j < s.Length; j++)
            {

                if (s.Substring(j, 1).IndexOfAny(new char[] {'a','e','i','o','u' }) == 0)
                {
                    iNumVowels++;
                }
                else if (s.Substring(j, 1).IndexOfAny(new char[] { 'b','c','d','f','g','h','j','k','l','m','n','p','q  ','r','s','t','v','w'}) == 0)
                {
                    iNumConsonants++;
                }

                
            }

            Console.WriteLine("There are {0} vowels and {1} consonants.", iNumVowels, iNumConsonants);
        }
    
    }

Reply With Quote
  #4  
Old November 30th, 2006, 09:58 AM
degsy degsy is offline
Contributing User
ASP Free God 2nd Plane (6000 - 6499 posts)
 
Join Date: Aug 2005
Location: North East, UK
Posts: 6,191 degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level)degsy User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 19 h 41 m 52 sec
Reputation Power: 121
If you want this in ASP then you can use an array function
http://www.aspisfun.com/code/parse/letterfreq.html
__________________
CyberTechHelp

Reply With Quote
  #5  
Old November 30th, 2006, 10:52 AM
asmoran asmoran is offline
ASPFree Know-It-All
ASP Free Novice (500 - 999 posts)
 
Join Date: Aug 2004
Posts: 930 asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level)asmoran User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 15 h 30 m 7 sec
Reputation Power: 325
Okay, here is some help

1) This one is simple. Like baby simple. If you don't know how to do this you're going to have a really hard time passing your class. I suggest you sit down with the instructor for some extra tutoring so you can better understand the concepts.

2) You're going to need a loop that steps through every number, starting at 0 and working up to the number entered. If the number is odd, you add it to your sum of odd numbers. If it's not odd, then it's even and you need to add it to your sum of even numbers. You will aslo need to add it to the total sum, regardless of if it's even or odd.

3) Similar to #2, except you need to step through each character in the entered string. Check to see if the character is a vowel, and if so you add one to your counter.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Need Programming Help ASAP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT