SlideShare a Scribd company logo
1 of 8
Download to read offline
C#: I need assitance on my code.. I'm getting an error message "Use of unassigned local
variable for "rectangle1 ==2, Square2 == 2, Triangle3 == 3" on the ShapeDemo Application.
Can you please help me? Here my code:
namespace Lab7ShapeDemo
{
class Triangle : GeometricFigure
{
public Triangle() { }
public Triangle (double height, double width)
{
}
public override double ComputeArea()
{
return ((1 / 2.0) * (width * height));
}
}
}// end on Triangle class
class Square : Triangle
{
public Square() { }
public Square(double height, double width) : base (height, height) { }
public Square (double heightWidth) : base (heightWidth, heightWidth) { }
public override double ComputeArea()
{
return base.ComputeArea();
}
}
} // end of Square class
class Rectangle : GeometricFigure
{
public Rectangle() { }
public Rectangle(double height, double width)
{
}
public override double ComputeArea()
{
return (height * width);
}
}
} //End of REctangle class
public GeometricFigure()
{
height = 0;
width = 0;
area = 0;
}
public GeometricFigure(double height, double width)
{
this.height = height;
this.width = width;
this.area = ComputeArea();
}
public abstract double ComputeArea();
}
} //End of GeometircFigure class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab7ShapeDemo
{
class ShapesDemo
{
static void Main(string[] args)
{
string Rectangle_HeightString;
string Rectangle_WidthString;
string Square_HeightString;
string Triangle_HeightString;
string Triangle_WidthString;
string Enter_NumberString;
double Rectangle_height;
double Rectangle_Width;
double Square_height;
double Triangle_Height;
double Triangle_Width;
double Enter_Number;
Console.Write("Choose a shape from the following options:");
Console.WriteLine("[1] Rectangle");
Console.WriteLine("[2] Square");
Console.WriteLine("[3} Triangle");
Console.Write("Enter the option number (or zero to terminate this program): ");
Enter_NumberString = Console.ReadLine();
Enter_Number = Convert.ToDouble(Enter_NumberString);
Console.WriteLine();
int rectangle1, Square2, Triangle3;
while (Enter_Number != 0)
{
if (rectangle1 == 1)
{
Console.Write("Enter the hight of the rectangle: ");
Rectangle_HeightString = Console.ReadLine();
Rectangle_height = Convert.ToDouble(Rectangle_HeightString);
Console.Write("Enter the width of the rectanlge: ");
Rectangle_WidthString = Console.ReadLine();
Rectangle_Width = Convert.ToDouble(Rectangle_WidthString);
Rectangle r1 = new Rectangle(Rectangle_height, Rectangle_Width);
displayGeometricFigure(r1);
}
else if (Square2 == 2)
{
Console.Write("Enter the height of the Square");
Square_HeightString = Console.ReadLine();
Square_height = Convert.ToDouble(Square_HeightString);
Square sq1 = new Square(Square_height);
displayGeometricFigure(sq1);
}
else if (Triangle3 == 3)
{
Console.Write("Enter the hight of the Triangle");
Triangle_HeightString = Console.ReadLine();
Triangle_Height = Convert.ToDouble(Triangle_HeightString);
Console.Write("Enter the width of the Triangle: ");
Triangle_WidthString = Console.ReadLine();
Triangle_Width = Convert.ToInt16(Triangle_WidthString);
Triangle t1 = new Triangle(Triangle_Height, Triangle_Width);
displayGeometricFigure(t1);
Console.WriteLine();
Console.ReadKey();
}
else
{
Console.Write("Enter the option number (or zero to terminate this program): ");
}
}
}
public static void displayGeometricFigure(GeometricFigure gf)
{
Console.WriteLine("The shape is: ", gf);
Console.WriteLine("The shape height is: ", gf);
Console.WriteLine("The shape width is: ", gf);
Console.WriteLine("The shape area is: ", gf);
Console.WriteLine();
}
}
}
Here the Demo Below:
Solution
Your code is incomplete it seems. You missed the starting lines of the GeometricFigure class.
Anyways, going through your code, and the error you specified, the problem is with the Main()
class. There, you read the option into a variable called Enter_Number, and that is what you
should compare in the If-else block, and not with variables recatangle1, square2, and triangle3.
Here is the modified version for you:
namespace Lab7ShapeDemo
{
class Triangle : GeometricFigure
{
public Triangle() { }
public Triangle (double height, double width)
{
}
public override double ComputeArea()
{
return ((1 / 2.0) * (width * height));
}
}
}// end on Triangle class
class Square : Triangle
{
public Square() { }
public Square(double height, double width) : base (height, height) { }
public Square (double heightWidth) : base (heightWidth, heightWidth) { }
public override double ComputeArea()
{
return base.ComputeArea();
}
}
} // end of Square class
class Rectangle : GeometricFigure
{
public Rectangle() { }
public Rectangle(double height, double width)
{
}
public override double ComputeArea()
{
return (height * width);
}
}
} //End of REctangle class
public GeometricFigure()
{
height = 0;
width = 0;
area = 0;
}
public GeometricFigure(double height, double width)
{
this.height = height;
this.width = width;
this.area = ComputeArea();
}
public abstract double ComputeArea();
}
} //End of GeometircFigure class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab7ShapeDemo
{
class ShapesDemo
{
static void Main(string[] args)
{
string Rectangle_HeightString;
string Rectangle_WidthString;
string Square_HeightString;
string Triangle_HeightString;
string Triangle_WidthString;
string Enter_NumberString;
double Rectangle_height;
double Rectangle_Width;
double Square_height;
double Triangle_Height;
double Triangle_Width;
double Enter_Number;
Console.Write("Choose a shape from the following options:");
Console.WriteLine("[1] Rectangle");
Console.WriteLine("[2] Square");
Console.WriteLine("[3} Triangle");
Console.Write("Enter the option number (or zero to terminate this program): ");
Enter_NumberString = Console.ReadLine();
Enter_Number = Convert.ToDouble(Enter_NumberString);
Console.WriteLine();
int rectangle1, Square2, Triangle3;
while (Enter_Number != 0)
{
if (Enter_Number == 1)
{
Console.Write("Enter the hight of the rectangle: ");
Rectangle_HeightString = Console.ReadLine();
Rectangle_height = Convert.ToDouble(Rectangle_HeightString);
Console.Write("Enter the width of the rectanlge: ");
Rectangle_WidthString = Console.ReadLine();
Rectangle_Width = Convert.ToDouble(Rectangle_WidthString);
Rectangle r1 = new Rectangle(Rectangle_height, Rectangle_Width);
displayGeometricFigure(r1);
}
else if (Enter_Number == 2)
{
Console.Write("Enter the height of the Square");
Square_HeightString = Console.ReadLine();
Square_height = Convert.ToDouble(Square_HeightString);
Square sq1 = new Square(Square_height);
displayGeometricFigure(sq1);
}
else if (Enter_Number == 3)
{
Console.Write("Enter the hight of the Triangle");
Triangle_HeightString = Console.ReadLine();
Triangle_Height = Convert.ToDouble(Triangle_HeightString);
Console.Write("Enter the width of the Triangle: ");
Triangle_WidthString = Console.ReadLine();
Triangle_Width = Convert.ToInt16(Triangle_WidthString);
Triangle t1 = new Triangle(Triangle_Height, Triangle_Width);
displayGeometricFigure(t1);
Console.WriteLine();
Console.ReadKey();
}
else
{
Console.Write("Enter the option number (or zero to terminate this program): ");
}
}
}
public static void displayGeometricFigure(GeometricFigure gf)
{
Console.WriteLine("The shape is: ", gf);
Console.WriteLine("The shape height is: ", gf);
Console.WriteLine("The shape width is: ", gf);
Console.WriteLine("The shape area is: ", gf);
Console.WriteLine();
}
}
}
I just highlighted the modifications I did. If you still face any problem, just get back to me.

More Related Content

Similar to C# I need assitance on my code.. Im getting an error message Us.pdf

Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxssuser562afc1
 
C++ Programming - 10th Study
C++ Programming - 10th StudyC++ Programming - 10th Study
C++ Programming - 10th StudyChris Ohk
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by HowardLearningTech
 
Howard type script
Howard   type scriptHoward   type script
Howard type scriptLearningTech
 
Type script by Howard
Type script by HowardType script by Howard
Type script by HowardLearningTech
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядомAndrey Akinshin
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docxajoy21
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined MethodPRN USM
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdfjeeteshmalani1
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsMuhammadTalha436
 

Similar to C# I need assitance on my code.. Im getting an error message Us.pdf (16)

Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docxassignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
assignmentTwoCar.javaassignmentTwoCar.javapackage assignmentTw.docx
 
C++ Programming - 10th Study
C++ Programming - 10th StudyC++ Programming - 10th Study
C++ Programming - 10th Study
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 
Howard type script
Howard   type scriptHoward   type script
Howard type script
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
Ch3
Ch3Ch3
Ch3
 
.NET 2015: Будущее рядом
.NET 2015: Будущее рядом.NET 2015: Будущее рядом
.NET 2015: Будущее рядом
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docx
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
C# example (Polymorphesim)
C# example (Polymorphesim)C# example (Polymorphesim)
C# example (Polymorphesim)
 
DotNet Conference: code smells
DotNet Conference: code smellsDotNet Conference: code smells
DotNet Conference: code smells
 
1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf1- Create a class called Point that has two instance variables, defi.pdf
1- Create a class called Point that has two instance variables, defi.pdf
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 

More from eyezoneamritsar

Identify 3 cell components that are shared in common between prokary.pdf
Identify 3 cell components that are shared in common between prokary.pdfIdentify 3 cell components that are shared in common between prokary.pdf
Identify 3 cell components that are shared in common between prokary.pdfeyezoneamritsar
 
How many pairs of wires are in a standard Ethernet cableDefend or.pdf
How many pairs of wires are in a standard Ethernet cableDefend or.pdfHow many pairs of wires are in a standard Ethernet cableDefend or.pdf
How many pairs of wires are in a standard Ethernet cableDefend or.pdfeyezoneamritsar
 
Fst can be used to measure the number of migrants per gegenetration .pdf
Fst can be used to measure the number of migrants per gegenetration .pdfFst can be used to measure the number of migrants per gegenetration .pdf
Fst can be used to measure the number of migrants per gegenetration .pdfeyezoneamritsar
 
How visual information is sent from the eye to the rest of the brain.pdf
How visual information is sent from the eye to the rest of the brain.pdfHow visual information is sent from the eye to the rest of the brain.pdf
How visual information is sent from the eye to the rest of the brain.pdfeyezoneamritsar
 
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdf
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdfFor coherently demodulated BPSK, what should EbN0 be in dB so as to.pdf
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdfeyezoneamritsar
 
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdf
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdfCisco Systems The Supply Chain Story11. Study the networked suppl.pdf
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdfeyezoneamritsar
 
Describe four threats to high data availability and at least one mea.pdf
Describe four threats to high data availability and at least one mea.pdfDescribe four threats to high data availability and at least one mea.pdf
Describe four threats to high data availability and at least one mea.pdfeyezoneamritsar
 
Describe the major interactions among organisms in a food web.So.pdf
Describe the major interactions among organisms in a food web.So.pdfDescribe the major interactions among organisms in a food web.So.pdf
Describe the major interactions among organisms in a food web.So.pdfeyezoneamritsar
 
Consider the following circle of radius 5 centered at the origin. Fi.pdf
Consider the following circle of radius 5 centered at the origin.  Fi.pdfConsider the following circle of radius 5 centered at the origin.  Fi.pdf
Consider the following circle of radius 5 centered at the origin. Fi.pdfeyezoneamritsar
 
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfWrite one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfeyezoneamritsar
 
Why are tourist destinations attempting to attract more visitors out.pdf
Why are tourist destinations attempting to attract more visitors out.pdfWhy are tourist destinations attempting to attract more visitors out.pdf
Why are tourist destinations attempting to attract more visitors out.pdfeyezoneamritsar
 
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdf
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdfWhich pair of words are synonymsA ephemeral--evanescentB euphon.pdf
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdfeyezoneamritsar
 
Which of the following embryonic materials is matched with a correct.pdf
Which of the following embryonic materials is matched with a correct.pdfWhich of the following embryonic materials is matched with a correct.pdf
Which of the following embryonic materials is matched with a correct.pdfeyezoneamritsar
 
We used 3 files with each lab project in Vivado. What do we call the.pdf
We used 3 files with each lab project in Vivado.  What do we call the.pdfWe used 3 files with each lab project in Vivado.  What do we call the.pdf
We used 3 files with each lab project in Vivado. What do we call the.pdfeyezoneamritsar
 
To determine the distance between short and black on chromosome II th.pdf
To determine the distance between short and black on chromosome II th.pdfTo determine the distance between short and black on chromosome II th.pdf
To determine the distance between short and black on chromosome II th.pdfeyezoneamritsar
 
High School Blues Evan and Alexia had been happily married for seven.pdf
High School Blues Evan and Alexia had been happily married for seven.pdfHigh School Blues Evan and Alexia had been happily married for seven.pdf
High School Blues Evan and Alexia had been happily married for seven.pdfeyezoneamritsar
 
Suppose within your Web browser, you click on a link to obtain a Webp.pdf
Suppose within your Web browser, you click on a link to obtain a Webp.pdfSuppose within your Web browser, you click on a link to obtain a Webp.pdf
Suppose within your Web browser, you click on a link to obtain a Webp.pdfeyezoneamritsar
 
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdf
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdfSupports cukaryotic cellsSolutionEukaryotes are the organisms h.pdf
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdfeyezoneamritsar
 
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdf
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdfBriefly define and describe what IASB and IFRS are.SolutionIAS.pdf
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdfeyezoneamritsar
 
Big idea Encapsulation A form of abstraction Interface Public data .pdf
Big idea Encapsulation A form of abstraction Interface Public data .pdfBig idea Encapsulation A form of abstraction Interface Public data .pdf
Big idea Encapsulation A form of abstraction Interface Public data .pdfeyezoneamritsar
 

More from eyezoneamritsar (20)

Identify 3 cell components that are shared in common between prokary.pdf
Identify 3 cell components that are shared in common between prokary.pdfIdentify 3 cell components that are shared in common between prokary.pdf
Identify 3 cell components that are shared in common between prokary.pdf
 
How many pairs of wires are in a standard Ethernet cableDefend or.pdf
How many pairs of wires are in a standard Ethernet cableDefend or.pdfHow many pairs of wires are in a standard Ethernet cableDefend or.pdf
How many pairs of wires are in a standard Ethernet cableDefend or.pdf
 
Fst can be used to measure the number of migrants per gegenetration .pdf
Fst can be used to measure the number of migrants per gegenetration .pdfFst can be used to measure the number of migrants per gegenetration .pdf
Fst can be used to measure the number of migrants per gegenetration .pdf
 
How visual information is sent from the eye to the rest of the brain.pdf
How visual information is sent from the eye to the rest of the brain.pdfHow visual information is sent from the eye to the rest of the brain.pdf
How visual information is sent from the eye to the rest of the brain.pdf
 
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdf
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdfFor coherently demodulated BPSK, what should EbN0 be in dB so as to.pdf
For coherently demodulated BPSK, what should EbN0 be in dB so as to.pdf
 
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdf
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdfCisco Systems The Supply Chain Story11. Study the networked suppl.pdf
Cisco Systems The Supply Chain Story11. Study the networked suppl.pdf
 
Describe four threats to high data availability and at least one mea.pdf
Describe four threats to high data availability and at least one mea.pdfDescribe four threats to high data availability and at least one mea.pdf
Describe four threats to high data availability and at least one mea.pdf
 
Describe the major interactions among organisms in a food web.So.pdf
Describe the major interactions among organisms in a food web.So.pdfDescribe the major interactions among organisms in a food web.So.pdf
Describe the major interactions among organisms in a food web.So.pdf
 
Consider the following circle of radius 5 centered at the origin. Fi.pdf
Consider the following circle of radius 5 centered at the origin.  Fi.pdfConsider the following circle of radius 5 centered at the origin.  Fi.pdf
Consider the following circle of radius 5 centered at the origin. Fi.pdf
 
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdfWrite one Conditional Signal Assignment VHDL code statement in the b.pdf
Write one Conditional Signal Assignment VHDL code statement in the b.pdf
 
Why are tourist destinations attempting to attract more visitors out.pdf
Why are tourist destinations attempting to attract more visitors out.pdfWhy are tourist destinations attempting to attract more visitors out.pdf
Why are tourist destinations attempting to attract more visitors out.pdf
 
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdf
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdfWhich pair of words are synonymsA ephemeral--evanescentB euphon.pdf
Which pair of words are synonymsA ephemeral--evanescentB euphon.pdf
 
Which of the following embryonic materials is matched with a correct.pdf
Which of the following embryonic materials is matched with a correct.pdfWhich of the following embryonic materials is matched with a correct.pdf
Which of the following embryonic materials is matched with a correct.pdf
 
We used 3 files with each lab project in Vivado. What do we call the.pdf
We used 3 files with each lab project in Vivado.  What do we call the.pdfWe used 3 files with each lab project in Vivado.  What do we call the.pdf
We used 3 files with each lab project in Vivado. What do we call the.pdf
 
To determine the distance between short and black on chromosome II th.pdf
To determine the distance between short and black on chromosome II th.pdfTo determine the distance between short and black on chromosome II th.pdf
To determine the distance between short and black on chromosome II th.pdf
 
High School Blues Evan and Alexia had been happily married for seven.pdf
High School Blues Evan and Alexia had been happily married for seven.pdfHigh School Blues Evan and Alexia had been happily married for seven.pdf
High School Blues Evan and Alexia had been happily married for seven.pdf
 
Suppose within your Web browser, you click on a link to obtain a Webp.pdf
Suppose within your Web browser, you click on a link to obtain a Webp.pdfSuppose within your Web browser, you click on a link to obtain a Webp.pdf
Suppose within your Web browser, you click on a link to obtain a Webp.pdf
 
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdf
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdfSupports cukaryotic cellsSolutionEukaryotes are the organisms h.pdf
Supports cukaryotic cellsSolutionEukaryotes are the organisms h.pdf
 
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdf
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdfBriefly define and describe what IASB and IFRS are.SolutionIAS.pdf
Briefly define and describe what IASB and IFRS are.SolutionIAS.pdf
 
Big idea Encapsulation A form of abstraction Interface Public data .pdf
Big idea Encapsulation A form of abstraction Interface Public data .pdfBig idea Encapsulation A form of abstraction Interface Public data .pdf
Big idea Encapsulation A form of abstraction Interface Public data .pdf
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

C# I need assitance on my code.. Im getting an error message Us.pdf

  • 1. C#: I need assitance on my code.. I'm getting an error message "Use of unassigned local variable for "rectangle1 ==2, Square2 == 2, Triangle3 == 3" on the ShapeDemo Application. Can you please help me? Here my code: namespace Lab7ShapeDemo { class Triangle : GeometricFigure { public Triangle() { } public Triangle (double height, double width) { } public override double ComputeArea() { return ((1 / 2.0) * (width * height)); } } }// end on Triangle class class Square : Triangle { public Square() { } public Square(double height, double width) : base (height, height) { } public Square (double heightWidth) : base (heightWidth, heightWidth) { } public override double ComputeArea() { return base.ComputeArea(); } } } // end of Square class class Rectangle : GeometricFigure { public Rectangle() { } public Rectangle(double height, double width) { } public override double ComputeArea()
  • 2. { return (height * width); } } } //End of REctangle class public GeometricFigure() { height = 0; width = 0; area = 0; } public GeometricFigure(double height, double width) { this.height = height; this.width = width; this.area = ComputeArea(); } public abstract double ComputeArea(); } } //End of GeometircFigure class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lab7ShapeDemo { class ShapesDemo { static void Main(string[] args) { string Rectangle_HeightString; string Rectangle_WidthString; string Square_HeightString; string Triangle_HeightString; string Triangle_WidthString;
  • 3. string Enter_NumberString; double Rectangle_height; double Rectangle_Width; double Square_height; double Triangle_Height; double Triangle_Width; double Enter_Number; Console.Write("Choose a shape from the following options:"); Console.WriteLine("[1] Rectangle"); Console.WriteLine("[2] Square"); Console.WriteLine("[3} Triangle"); Console.Write("Enter the option number (or zero to terminate this program): "); Enter_NumberString = Console.ReadLine(); Enter_Number = Convert.ToDouble(Enter_NumberString); Console.WriteLine(); int rectangle1, Square2, Triangle3; while (Enter_Number != 0) { if (rectangle1 == 1) { Console.Write("Enter the hight of the rectangle: "); Rectangle_HeightString = Console.ReadLine(); Rectangle_height = Convert.ToDouble(Rectangle_HeightString); Console.Write("Enter the width of the rectanlge: "); Rectangle_WidthString = Console.ReadLine(); Rectangle_Width = Convert.ToDouble(Rectangle_WidthString); Rectangle r1 = new Rectangle(Rectangle_height, Rectangle_Width); displayGeometricFigure(r1); } else if (Square2 == 2) { Console.Write("Enter the height of the Square"); Square_HeightString = Console.ReadLine(); Square_height = Convert.ToDouble(Square_HeightString); Square sq1 = new Square(Square_height);
  • 4. displayGeometricFigure(sq1); } else if (Triangle3 == 3) { Console.Write("Enter the hight of the Triangle"); Triangle_HeightString = Console.ReadLine(); Triangle_Height = Convert.ToDouble(Triangle_HeightString); Console.Write("Enter the width of the Triangle: "); Triangle_WidthString = Console.ReadLine(); Triangle_Width = Convert.ToInt16(Triangle_WidthString); Triangle t1 = new Triangle(Triangle_Height, Triangle_Width); displayGeometricFigure(t1); Console.WriteLine(); Console.ReadKey(); } else { Console.Write("Enter the option number (or zero to terminate this program): "); } } } public static void displayGeometricFigure(GeometricFigure gf) { Console.WriteLine("The shape is: ", gf); Console.WriteLine("The shape height is: ", gf); Console.WriteLine("The shape width is: ", gf); Console.WriteLine("The shape area is: ", gf); Console.WriteLine(); } } } Here the Demo Below: Solution Your code is incomplete it seems. You missed the starting lines of the GeometricFigure class.
  • 5. Anyways, going through your code, and the error you specified, the problem is with the Main() class. There, you read the option into a variable called Enter_Number, and that is what you should compare in the If-else block, and not with variables recatangle1, square2, and triangle3. Here is the modified version for you: namespace Lab7ShapeDemo { class Triangle : GeometricFigure { public Triangle() { } public Triangle (double height, double width) { } public override double ComputeArea() { return ((1 / 2.0) * (width * height)); } } }// end on Triangle class class Square : Triangle { public Square() { } public Square(double height, double width) : base (height, height) { } public Square (double heightWidth) : base (heightWidth, heightWidth) { } public override double ComputeArea() { return base.ComputeArea(); } } } // end of Square class class Rectangle : GeometricFigure { public Rectangle() { } public Rectangle(double height, double width) { } public override double ComputeArea()
  • 6. { return (height * width); } } } //End of REctangle class public GeometricFigure() { height = 0; width = 0; area = 0; } public GeometricFigure(double height, double width) { this.height = height; this.width = width; this.area = ComputeArea(); } public abstract double ComputeArea(); } } //End of GeometircFigure class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Lab7ShapeDemo { class ShapesDemo { static void Main(string[] args) { string Rectangle_HeightString; string Rectangle_WidthString; string Square_HeightString; string Triangle_HeightString; string Triangle_WidthString;
  • 7. string Enter_NumberString; double Rectangle_height; double Rectangle_Width; double Square_height; double Triangle_Height; double Triangle_Width; double Enter_Number; Console.Write("Choose a shape from the following options:"); Console.WriteLine("[1] Rectangle"); Console.WriteLine("[2] Square"); Console.WriteLine("[3} Triangle"); Console.Write("Enter the option number (or zero to terminate this program): "); Enter_NumberString = Console.ReadLine(); Enter_Number = Convert.ToDouble(Enter_NumberString); Console.WriteLine(); int rectangle1, Square2, Triangle3; while (Enter_Number != 0) { if (Enter_Number == 1) { Console.Write("Enter the hight of the rectangle: "); Rectangle_HeightString = Console.ReadLine(); Rectangle_height = Convert.ToDouble(Rectangle_HeightString); Console.Write("Enter the width of the rectanlge: "); Rectangle_WidthString = Console.ReadLine(); Rectangle_Width = Convert.ToDouble(Rectangle_WidthString); Rectangle r1 = new Rectangle(Rectangle_height, Rectangle_Width); displayGeometricFigure(r1); } else if (Enter_Number == 2) { Console.Write("Enter the height of the Square"); Square_HeightString = Console.ReadLine(); Square_height = Convert.ToDouble(Square_HeightString); Square sq1 = new Square(Square_height); displayGeometricFigure(sq1);
  • 8. } else if (Enter_Number == 3) { Console.Write("Enter the hight of the Triangle"); Triangle_HeightString = Console.ReadLine(); Triangle_Height = Convert.ToDouble(Triangle_HeightString); Console.Write("Enter the width of the Triangle: "); Triangle_WidthString = Console.ReadLine(); Triangle_Width = Convert.ToInt16(Triangle_WidthString); Triangle t1 = new Triangle(Triangle_Height, Triangle_Width); displayGeometricFigure(t1); Console.WriteLine(); Console.ReadKey(); } else { Console.Write("Enter the option number (or zero to terminate this program): "); } } } public static void displayGeometricFigure(GeometricFigure gf) { Console.WriteLine("The shape is: ", gf); Console.WriteLine("The shape height is: ", gf); Console.WriteLine("The shape width is: ", gf); Console.WriteLine("The shape area is: ", gf); Console.WriteLine(); } } } I just highlighted the modifications I did. If you still face any problem, just get back to me.