• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

C# Programming - my assignment was to write code making Fido bark 5 times (while loop) and run 10 times (for Loop)

Question

Vickie Primes    1

I am getting error messages and the code won't build.

 

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

namespace Assignment07
{using System; using System.Collections.Generic; using System.Linq; using System.Text; 
 
namespace Assignment07 {     class Dog     {         public void bark(string dogsName)         {             Console.WriteLine(dogsName + " is barking");         }         public void run(string dogsName)         {             Console.WriteLine(dogsName + " is running");         }     } 
 
    class Program     {         static void Main(string[] args)         { 
 
            Dog fido = new Dog(); 
 
            fido.bark("Fido"); 
 
            fido.run("Fido"); 
 
            Console.Write("Hit any key to close"); Console.ReadKey(true);         }     } } 

    class Dog
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Assignment 07");
            Console.WriteLine("This program is written by Vickie Primes");
        }

        public void bark (string dogsName)
        { 
            int barking = 0;
            while(barking < 5){
                barking = barking +1;
                {
                Console.WriteLine(dogsName + " is barking");
               
        public  string running { get; set; }}
      
                   
        public void Run(string dogsName)
        {
                for (var i = 0; i < 10; i++)
                running = "1 + 1";
                Console.WriteLine(dogsName + "is running");

            Dog fido = new Dog();

            fido.bark("Fido");

            fido.run("Fido");

            Console.Write("Hit any key to close"); Console.ReadKey(true);
        }
    
public  string running { get; set; }}
      
    
 

  • Like 1

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
+Red King    2,466

That code is unreadable - use code tags. You have class dog twice.

Share this post


Link to post
Share on other sites
  • 0
badmouse    3
using System;
namespace ConsoleApp1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var myDog = new Dog("Vickie");

            var barking = 0;
            while(barking < 5)
            {
                barking++;
                myDog.Bark();
            }

            for(var running = 0; running < 10; running ++)
            {
                myDog.Run();
            }
        }
    }

    class Dog
    {
        public string Name { get; set; }
        public Dog(string name)
        {
            Name = name;
        }
        public void Run() {
            Console.WriteLine(Name + " is running");
        }
        public void Bark() {
            Console.WriteLine(Name + " is barking");
        }
    }
}

LOL. Hope you become an awesome programmer one day :)

  • Like 1

Share this post


Link to post
Share on other sites
  • 0
RzmmDX    21

You have 2 static main methods.

Share this post


Link to post
Share on other sites
  • 0
+Gary7    7,372

Try doing your own home work..:D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.