2 개 코드를 하나로 결합하려고하는데 많은 문제가 있습니다. 코드는 그룹 번호와 기부 금액을 물어보고 0을 누를 때까지 되돌아 가야합니다. 0을 누르면 모든 그룹의 총계가 표시됩니다. 여기C# 스위치 루프, 각 경우에 대해 합계가 있습니다.
코드 1 개
using System;
public class TotalPurchase
{
public static void Main()
{
double donation;
double total = 0;
string inputString;
const double QUIT = 0;
Console.WriteLine("Please enter the amount of the contribution: ");
inputString = Console.ReadLine();
donation = Convert.ToDouble(inputString);
while(donation != QUIT)
{
total += donation;
Console.WriteLine("Enter next donation amount, or " +
QUIT + " to quit ");
inputString = Console.ReadLine();
donation = Convert.ToDouble(inputString);
}
Console.WriteLine("Your total is {0}", total.ToString("C"));
}
}
코드 2
using System;
namespace donate
{
class donate
{
public static void Main()
{
begin:
string group;
int myint;
Console.WriteLine("Please enter group number (4, 5, or 6)");
Console.WriteLine("(0 to quit): ");
group = Console.ReadLine();
myint = Int32.Parse(group);
switch (myint)
{
case 0:
Console.WriteLine("Bye.");
break;
case 4:
case 5:
case 6:
double donation;
string inputString;
Console.WriteLine("Please enter the amount of the contribution: ");
inputString = Console.ReadLine();
donation = Convert.ToDouble(inputString);
goto begin;
default:
Console.WriteLine("Incorrect grade number.", myint);
goto begin;
}
}
}
}
그래서 기본적으로 내가 2 코드를 사용하여 각 그룹에 대한 총을 찾으려는 2 개 개의 다른 코드입니다.
도움을 주시면 감사하겠습니다.
설명이 포함 된 학교 프로젝트입니까? –