Visual Studio Development Bookmark and Share   
 index > Visual C# Express Edition > Class project
 

Class project

//

// Program by Matt Cole

// Purpose: Calculate Rectangle Area ;

using

 

System; // !! Allows us to shorten many statements!

class

 

Rectangle

{

 

// Variables that hold data & info in RAM while program runs

 

double width, height, area, perim;

 

 

// Greet user

 

Console.WriteLine( "This calculates rectangle area and perimeter." );

 

 

// Get width & change string to number

 

Console.Write ( "Enter the width: ");

12=

 

Convert.ToDouble( Console.Readline( ) );

 

 

// Get height & changle string to number

 

Console.Write( "Enter the height" );

3=

 

Convert.ToDouble ( Console.Readline( ) );

 

 

// Calculate area and perimeter

p30 = ( w12 + h3 ) * 2 ;

a36 = w12 + h3 ;

 

// Report to user

 

Console.Readline( "\n|tPerimeter is " + perim.ToString( ) + " units." );

 

 

Console.Readline( "\tArea is " + perim.ToString + "units" );

 

 

// Check for big area size OR big perimeter size

 

if( area >= 25 || perim > 20 )

 

 

Console.Writeline( "Big rectangle!" );

 

 

else

 

Console.Writeline( "Small rectangle!" );

 

}

}

 

  • Edited byHawknTaffurs Tuesday, October 06, 2009 9:38 PMI have recieved 22 errors using Visual Studio 2008, it says I have invalid token errors and highlights my use of parenthesis on every line. Im only asking this as a last resort because no matter how I change them, i still recieve these errors. Thanks
  •  
HawknTaffurs  Tuesday, October 06, 2009 9:10 PM
There are a bunch of things you need to watch out for.
C# is case sensitive for one.
There are a number of reads that should be writes
you define some variables, but then use odd substitutes.
you should also ensure that the user actually enters a number when prompted.

In any case, this should get you going again:


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double width, height, area, perim;

            // Greet user
            Console.WriteLine( "This calculates rectangle area and perimeter." );

            // Get width & change string to number
            Console.Write("Enter the width: ");
            width = Convert.ToDouble( Console.ReadLine( ) );

            // Get height & changle string to number
            Console.Write("Enter the height: ");
            height = Convert.ToDouble ( Console.ReadLine( ) );

            // Calculate area and perimeter
            perim = ( width + height ) * 2 ;
            area = width * height ;

            // Report to user
            Console.WriteLine( "\tPerimeter is: " + perim.ToString( ) + " units." );
            Console.WriteLine("\tArea is: " + area.ToString() + " units.");

            // Check for big area size OR big perimeter size
            if (area >= 25 || perim >= 20)
            {
                Console.WriteLine("Big rectangle!");
            }
            else
            {
                Console.WriteLine("Small rectangle!");
            }
        }
    }
}

jgalley  Tuesday, October 06, 2009 9:46 PM
I'm getting 22 errors as well with your code.  You'll have to put it in a method.

using System;

class Program {
    static void Main(string[] args) {
        // Put your code here.
    }
}


Hans Passant.
nobugz  Tuesday, October 06, 2009 9:46 PM
Hmm.  No question in the actual post, just on the subject line.  "How can I fix this?"

First you can "fix" it up by using the Code Formatter to post code.  Why do I say that?  Try to copy and paste that into a new sample project file.
You can also paste your code into MS Notepad, and then copy and paste from there into the forums.  I usually go that route.

Second, you can actually ask a question besides the implied request to fix---what happens to appear to be your homework---for you.  Describe what errors you get if any, and on which line of code errors occur.  Demonstrate that you have at least tried to solve the problem on your own. 

This may sound harsh, but there is only one way to learn to be a good developer.  Brain busting practice, practice, practice.
Mark the best replies as answers. "Fooling computers since 1971."

EDIT:  And no I do not see a problem at first glance.  The formatting is hard on my bad eyes.
Rudedog2  Tuesday, October 06, 2009 9:34 PM

I have recieved 22 errors using Visual Studio 2008, it says I have invalid token errors and highlights my use of parenthesis on every line. Im only asking this as a last resort because no matter how I change them, i still recieve these errors. Any advice as to how I can fix these "invalid tokens" would be much appreciated. Thanks

HawknTaffurs  Tuesday, October 06, 2009 9:40 PM
Please use the Code Formatting Tool to post code. 
It is far too easy to use and unfortunately it can unfairly demonstrate a lazy streak on your part, be it true or false.
Most of the veterans---the ones who know the most---tend to ignore such threads.  Particularly ones that resemble homework.

Your respoonse is in a type font that is too small for someone like me to read without straining my eyes.


Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Tuesday, October 06, 2009 9:45 PM
There are a bunch of things you need to watch out for.
C# is case sensitive for one.
There are a number of reads that should be writes
you define some variables, but then use odd substitutes.
you should also ensure that the user actually enters a number when prompted.

In any case, this should get you going again:


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double width, height, area, perim;

            // Greet user
            Console.WriteLine( "This calculates rectangle area and perimeter." );

            // Get width & change string to number
            Console.Write("Enter the width: ");
            width = Convert.ToDouble( Console.ReadLine( ) );

            // Get height & changle string to number
            Console.Write("Enter the height: ");
            height = Convert.ToDouble ( Console.ReadLine( ) );

            // Calculate area and perimeter
            perim = ( width + height ) * 2 ;
            area = width * height ;

            // Report to user
            Console.WriteLine( "\tPerimeter is: " + perim.ToString( ) + " units." );
            Console.WriteLine("\tArea is: " + area.ToString() + " units.");

            // Check for big area size OR big perimeter size
            if (area >= 25 || perim >= 20)
            {
                Console.WriteLine("Big rectangle!");
            }
            else
            {
                Console.WriteLine("Small rectangle!");
            }
        }
    }
}

jgalley  Tuesday, October 06, 2009 9:46 PM
I'm getting 22 errors as well with your code.  You'll have to put it in a method.

using System;

class Program {
    static void Main(string[] args) {
        // Put your code here.
    }
}


Hans Passant.
nobugz  Tuesday, October 06, 2009 9:46 PM
Thanks guys.  Much better.

HawknTuffurs,

Don't expect someone to just simply fix it for you.
Be prepared to be cattle prodded in the right direction.

"Give a man a fish and you feed him for a day.  Teach a man to fish, and you feed him for life."

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Tuesday, October 06, 2009 9:50 PM
Thank you, you were a great help, sorry I wasnt more helpful on my end. Im a first time user for this website and am just learning this programming myself. Just needed some help. Thanks Again
HawknTaffurs  Tuesday, October 06, 2009 9:58 PM

You can use google to search for other answers

Custom Search

More Threads

• Random picture in picturebox
• Replace Recources in an .exe
• DOS Prompt
• How to get Table Name from Dataset
• Problems with active x control
• XML and Visual c# problem
• Shadows
• Project default namespace not being applied
• help reqd starting new application with the main command
• mdi child focushed form tracking