This program is for question 4. When the area code is 262 program is executing well but program is not working for other area codes. Please correct the error. I attach the question.
using System;
namespace _6e4
{
class Program
{
static void Main(string[] args)
{
int[] code = {262, 414, 608, 715, 815, 920};
double[] rate = {0.07, 0.10, 0.05, 0.16, 0.24, 0.14};
double cost;
Console.Write("Enter the area code ");
string s = Console.ReadLine();
Console.Write("Number of minutes talk ");
string t = Console.ReadLine();
for (int x = 0; x < code.Length; ++x)
{
if(Convert.ToInt32(s)==code[x])
{
cost = rate[x] * Convert.ToDouble(t);
Console.WriteLine("Total cost = {0}", cost.ToString("C"));
x = code.Length;
}
Console.ReadKey();
}
}
}
}
Loading
VulpesPosted Jan 7, 2012, 2:54 PM
It must therefore have an sEnum property which we can access using the usual 'object.member' syntax.
Posted Jan 7, 2012, 2:46 PM
number.sEnum (object dot sEnum) is indicating what?
VulpesPosted Jan 7, 2012, 1:28 PM
Posted Jan 7, 2012, 9:56 AM
if (this.sEnum > number.sEnum)
class School : IComparable
{
public string nameSchool { get; set; }
public int sEnum { get; set; }
public int CompareTo(School number)
{
int returnVal;
if (this.sEnum > number.sEnum) //???????????????
returnVal = 1;
else
if (this.sEnum < number.sEnum)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
}
VulpesPosted Jan 3, 2012, 9:11 AM
Here zipNo == false and so !zipNo == true.
Hence the 'if' statement will execute.
Posted Jan 3, 2012, 8:56 AM
From this program I understood that IF statement represents the action that will take place only if the expression evaluates as true, whatever way the relevant variable is defined. Here the variable zipNo is defined as bool zipNo = false;
I wish to know whether my understanding is correct.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
bool zipNo = false;
if (!zipNo)
{
Console.WriteLine("Company not delivered to Zip");
}
Console.ReadKey();
}
}
}
VulpesPosted Jan 3, 2012, 4:35 AM
So, if it's not true, it's false and, if it's not false, it's true.
An 'if' statement only executes if its condition is true.
When applied to a bool, the '!' operator changes a true value to false and vice versa.
If zipCode is false, then !zipCode is true and so the 'if' statement does execute.
Posted Jan 2, 2012, 7:28 PM
Suppose we say input does not match the given zip code. bool zipNo = false; is define in the program therefore if(!zipNo) means if(notFalse) as this is opposite to what was define in the program, in this circumstances how program can execute the statement within the if.
VulpesPosted Jan 2, 2012, 6:56 PM
"Company not delivered to Zip "
followed by whatever the user input.
zipNo will be false if whatever zip code the user entered is not in the array.
Posted Jan 2, 2012, 3:37 PM
if (!zipNo)
{
Console.WriteLine("Company not delivered to Zip {0}", s);
}
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] zip = new string[5] { "1000", "2000", "3000", "4000", "5000" };
Console.Write("Entre a ZIP code ");
string s = Console.ReadLine();
bool zipNo = false;
for (int x = 0; x < zip.Length; ++x)
{
if (Equals(s, zip[x]))
{
Console.WriteLine("Company dilivers {0}", zip[x]);
zipNo = true;
x = zip.Length;
}
}
if (!zipNo)
{
Console.WriteLine("Company not delivered to Zip {0}", s); //?????????????????
}
Console.ReadKey();
}
}
}
VulpesPosted Dec 28, 2011, 9:34 AM
Posted Dec 28, 2011, 8:56 AM
VulpesPosted Dec 27, 2011, 6:38 PM
This code:
should be:
{
}
Posted Dec 27, 2011, 6:31 PM
VulpesPosted Dec 27, 2011, 5:56 PM
Posted Dec 25, 2011, 8:07 PM
"THERE IS NO ENROLLMENT FIGURE MORE THAN....." This message must come on the console screen when appropriate. How it is possible because if-else statement can't be used in this for loop.
VulpesPosted Dec 25, 2011, 7:44 PM
If you want to use foreach instead of for, the code will be:
Posted Dec 25, 2011, 4:08 PM
using System;
namespace _6e11
{
class CarRecords
{
static void Main(string[] args)
{
Car[] car = new Car[5];
car[0] = new Car(1111, "Fiat", "11000", "Black", 5000);
car[1] = new Car(2222, "Honda", "2000", "Red", 6000);
car[2] = new Car(3333, "Camery", "XYZ100", "Green", 7000);
car[3] = new Car(4444, "Nissan", "JXA300", "Blue", 8000);
car[4] = new Car(5555, "Moris", "3BS100", "White", 9000);
DisPlayFleet(car[0], car[1], car[2]);//18,000
DisPlayFleet(car[0], car[1], car[2], car[3]);//26,000
DisPlayFleet(car[0], car[1], car[2], car[3], car[4]);//35,000
Console.ReadKey();
}
public static void DisPlayFleet(params Car[] cArray)
{
int sum=0, carPrice=0;
for (int x = 0; x < cArray.Length; ++x ) //how to use foreach instead of for
{
sum = sum + cArray[x].price;
carPrice = cArray[x].price;
Console.WriteLine("Price of Car[{0}] = {1}", x, carPrice.ToString("C"));
}
Console.WriteLine("Sum = {0}", sum.ToString("C"));
Console.WriteLine();
}
}
}
class Car
{
public int idNumber { get; set; }
public string make { get; set; }
public string model { get; set; }
public string colour { get; set; }
public int price { get; set; }
public Car(int idNumber, string make, string model, string colour, int price)
{
this.idNumber = idNumber;
this.make = make;
this.model = model;
this.colour = colour;
this.price = price;
}
}
VulpesPosted Dec 25, 2011, 5:08 AM
Posted Dec 24, 2011, 10:54 PM
//pdf241
using System;
public class Prices
{
public static void Main()
{
Prices[] pArray = new Prices[20]; ;
double ePrice, sum = 0, average = 0;
for (int x = 0; x < pArray.Length; ++x)
{
pArray[x] = new Prices();
Console.Write("Prices #{0} $", x + 1);
ePrice = Convert.ToDouble(Console.ReadLine());
pArray[x].SetPrice(ePrice);
sum = sum + ePrice;
average = sum / pArray.Length;
}
Console.WriteLine("\nTotal: {0}", sum.ToString("c"));
Console.WriteLine("\nPrices less than $5.00");
Console.WriteLine("----------------------");
for (int x = 0; x < pArray.Length; ++x)
if (pArray[x].GetPrice() < 5)
Console.WriteLine("Prices #{0} ${1}", x + 1, pArray[x].GetPrice());
Console.WriteLine("\nAverage: ${0}", average.ToString("f2"));
Console.WriteLine("\nPrices higher than average");
Console.WriteLine("--------------------------");
for (int x = 0; x < pArray.Length; ++x)
if (pArray[x].GetPrice() > average)
Console.WriteLine("Prices #{0} ${1}", x + 1, pArray[x].GetPrice());
Console.WriteLine();
Console.ReadKey();
}
}
class Prices
{
double values;
public double GetPrice()
{
return values;
}
public void SetPrice(double p)
{
values = p;
}
}
VulpesPosted Dec 24, 2011, 8:39 AM
Posted Dec 24, 2011, 7:32 AM
For example in a question (Employee empArray = new Employee[7];) the object empArray contains employee ID and salary and you have to use these two properties to derive answer therefore separate class in necessary.
VulpesPosted Dec 24, 2011, 7:06 AM
So I'd use:
double[] prices = new double[20];
Posted Dec 24, 2011, 6:19 AM
VulpesPosted Dec 24, 2011, 4:57 AM
It only covers questions 4 to 8 inclusive.
Posted Dec 23, 2011, 9:59 PM
Prices[] prices = new Prices[20];
or
double[] prices = new double[20];
VulpesPosted Dec 23, 2011, 1:18 PM
There isn't a member called 'percentcommission' and (if you know what extension methods are) there isn't one of those either which is in scope and can apply to a double instance.
Hence the error.
Posted Dec 23, 2011, 1:02 PM
Error message
'double' does not contain a definition for 'percentcommission' and no extension method 'percentcommission' accepting a first argument of type 'double' could be found (are you missing a using directive or an assembly reference?)
using System;
public class Commission
{
public static void Main()
{
double[] carprices = {0, 15000, 24000};
double[] percentcommission = {0.05, 0.07, 0.10};
int x = 2;
Console.Write("Enter the car price: $");
double price = Convert.ToDouble(Console.ReadLine());
while (x >= 0 && price < carprices[x])
--x;
Console.WriteLine("Commission: {0}", (price.percentcommission[x]).ToString("c")); //dot(.) instead of *
Console.ReadKey();
}
}
VulpesPosted Dec 23, 2011, 8:16 AM
Posted Dec 22, 2011, 6:23 PM
while (x >= 0 && miles < distance[x]) - working
while (x >= 0 && miles < 500) – not working
using System;
public class WhippetBus
{
public static void Main()
{
double[] distance = { 0, 100, 300, 500 };
int[] ticketprice = { 25, 40, 55, 70 };
int x = 3;
Console.Write("Enter Distance in miles: ");
double miles = Convert.ToDouble(Console.ReadLine());
while (x >= 0 && miles < distance[x])
--x;
Console.WriteLine("Ticket Price for {0} mile is {1}", miles, ticketprice[x].ToString("c"));
Console.ReadKey();
}
}
/*
Enter Distance in miles: 400
Ticket Price for 400 mile is $55.00
Enter Distance in miles: 700
Ticket Price for 700 mile is $70.00
*/
VulpesPosted Dec 22, 2011, 1:45 PM
What makes you think it's not working properly for codes other than 262?