English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

For some reason the compiler is not liking the for loops (I think) I can't seem to figure out why my code isn't working, can anyone help?

public static void Main()
{
double BASIC_DOG_PRICE = 2.00;
double CHILI_PRICE = 0.69;
double CHEESE_PRICE = 0.49;
String wantChili, wantCheese;
double price;
Console.Write("Do you want chili on your dog?" );
inputString wantChili = Console.ReadLine;
Console.Write("Do you want cheese on your dog?" );
inputString wantCheese = Console.ReadLine;

for wantChili == 'Y'
for wantCheese == 'Y'
price = BASIC_DOG_PRICE + CHILI_PRICE + CHEESE_PRICE;

forBASIC_DOG_PRICE + CHILI_PRICE;

for wantCheese == 'Y
for(BASIC_DOG_PRICE + CHEESE_PRICE);

for (BASIC_DOG_PRICE);

Console.WriteLine("Your total is {0}", price.ToString("C"));

}
}

2006-12-16 16:08:57 · 4 answers · asked by Christina 2 in Computers & Internet Programming & Design

4 answers

this fixes it a little, but only allows you to order 1 hot dog. If you need a loop to order more then 1 hot dog before showing the total it is more complicated

public static void Main()
{
double BASIC_DOG_PRICE = 2.00;
double CHILI_PRICE = 0.69;
double CHEESE_PRICE = 0.49;
String wantChili, wantCheese;
double price;
Console.Write("Do you want chili on your dog?" );
inputString wantChili = Console.ReadLine;
Console.Write("Do you want cheese on your dog?" );
inputString wantCheese = Console.ReadLine;

price = BASIC_DOG_PRICE;

if( wantChili == 'Y')
{
if(for wantCheese == 'Y')
{
price += CHILI_PRICE + CHEESE_PRICE;
}
price += CHILI_PRICE;
}
Console.WriteLine("Your total is {0}", price.ToString("C"));
}

2006-12-16 16:52:59 · answer #1 · answered by Bradford K 4 · 0 0

Um, well, there isn't much in there for a compiler to like at all. You haven't actually written a single for loop at all. Just look in the language reference to see what constitutes a for loop and how it works, you are so far out here that it would take a couple of pages of typing to put you anywhere near right.

You can achieve what I think you want to do with if statements.

2006-12-17 00:31:03 · answer #2 · answered by Stewart H 4 · 0 0

Yep - you do need some help! :) I'm guessing this is a homework assignment?

I don't even know where to start - there's way too much wrong with this.

First off, the for keyword is used to perform a loop and has the format of:
for (initializer; test condition; interive operation) {
...
}

You really need to plan out what you want to do in pseudocode and then write the code.

2006-12-17 00:17:50 · answer #3 · answered by BigRez 6 · 0 0

The first error is there must be space between for and BASIC_DOG_PRICE + CHILI_PRICE; in line :- forBASIC_DOG_PRICE + CHILI_PRICE; then no semicolon(;) in the for loops. Also put curved braces in for loops (()) in case of having additions. eg:- instead of, forBASIC_DOG_PRICE + CHILI_PRICE put for(BASIC_DOG_PRICE + CHILI_PRICE)

2006-12-17 00:23:16 · answer #4 · answered by rayden 2 · 0 0

fedest.com, questions and answers