-4

私はC#を使用しています。ユーザーが数値を入力できるようにしようとしています (IE: いくつ必要ですか?)、その値を取得し、税金と合計を計算します。これを行う方法がわからず、誰かが私に見せてくれるかどうか疑問に思いましたか? 私の現在のスクリプトは以下の通りです:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Infinate Happiness Ranch.\nPlease enter your order information bellow. ");

            Console.WriteLine();

            Console.WriteLine("Please enter your first and last name:");
            string FirstName = Console.ReadLine();

            Console.WriteLine("Please enter your street address:");
            string Address = Console.ReadLine();

            Console.WriteLine("Please enter your city:");
            string City = Console.ReadLine();

            Console.WriteLine("Please enter your two letter state abbreviation:");
            string StateCode = Console.ReadLine();

            Console.WriteLine("Please enter your zip code:");
            string ZipCode = Console.ReadLine();

            Console.WriteLine("Please enter the number of Tribbles \nyou wish to purchase for $29.99 plus tax");
            string NumberOrdered = Console.ReadLine();

            Console.WriteLine("Invoice \nName {0}", FirstName);
            Console.WriteLine("Address {0}", Address);
            Console.WriteLine("City {0}", City);
            Console.WriteLine("StateCode {0}", StateCode);
            Console.WriteLine("ZipCode {0}", ZipCode);
            Console.WriteLine("NumberOrdered {0}", NumberOrdered);
            // PROGRAM WORKS UNTIL HERE.
            NumberOrdered = m;
            TotalBeforeTax = m * 29.99; //'n' is total b4 tax
            o = n * 0.9;// 'o' is total tax due
            p = o + n; // 'p' is total due

            Console.WriteLine("Your total is {0} {1}", n);
            Console.WriteLine("Your tax is {0}", o);
            Console.WriteLine("Your total charge is {0}", p);
            Console.WriteLine("Thank you for your order");
            Console.WriteLine();

            //Console.WriteLine("Name:" + FirstName);
            Console.Read();    
        }
    }
}
4

4 に答える 4

0

いくつかの変数を宣言し、いくつかの値を割り当てるのを忘れました。

これを試して:

static float m;
static float n;
static float o;
static float p;
static float TotalBeforeTax;
static void Main(string[] args)
{
    Console.WriteLine("Welcome to  Infinate Happiness Ranch.\nPlease enter your order information bellow. ");
    Console.WriteLine();

    Console.WriteLine("Please enter your first and last name:");
    string FirstName = Console.ReadLine();

    Console.WriteLine("Please enter your street address:");
    string Address = Console.ReadLine();

    Console.WriteLine("Please enter your city:");
    string City = Console.ReadLine();

    Console.WriteLine("Please enter your two letter state abreviation:");
    string StateCode = Console.ReadLine();

    Console.WriteLine("Please enter your zip code:");
    string ZipCode = Console.ReadLine();

    Console.WriteLine("Please enter the number of Tribbles \nyou wish to purchase for $29.99 plus tax");
    string NumberOrdered = Console.ReadLine();

    Console.WriteLine("Invoice \nName {0}", FirstName);
    Console.WriteLine("Address {0}", Address);
    Console.WriteLine("City {0}", City);
    Console.WriteLine("StateCode {0}", StateCode);
    Console.WriteLine("ZipCode {0}", ZipCode);
    Console.WriteLine("NumberOrdered {0}", NumberOrdered);
    //PROGRAM WORKS UNTIL HERE ? HELP ? ? ? ? ?
    //NumberOrdered = m;
    m = float.Parse(NumberOrdered);
    TotalBeforeTax = m * 29.99f; //'n' is total b4 tax
    n = TotalBeforeTax;
    o = n * 0.9f;//'o' is total tax due
    p = o + n; //'p' is total due

    Console.WriteLine("Your total is {0}", n);
    Console.WriteLine("Your tax is {0}", o);
    Console.WriteLine("Your total charge is {0}", p);
    Console.WriteLine("Thank you for your order");
    Console.WriteLine();
    Console.Read();
}

お役に立てれば !

于 2013-10-14T17:26:19.697 に答える
0

文字列を解析する必要があります

int ordered = int.Parse(NumberOrdered);

そして、この整数で計算を続けます。

于 2013-10-14T17:09:20.850 に答える
-3

ちょっとしたアドバイスですが、次のように Console.WriteLine() に文字列以外の変数を含めることができます。

Console.WriteLine("Your tax is " + o);

これは、ほとんどのプロの開発者が行うことです。複雑な C/C++ スタイルの解析は必要ありません。

また、変数 o と p を宣言していないようです。これを試して:

double o = Convert.toDouble(n * 0.9);

また

ダブル o = (ダブル)(n * 0.9);

于 2013-10-14T17:08:43.320 に答える