所以我有一些我正在上学的东西,但我一直在遇到问题并无法解决.我几乎完成了项目,但我一直在遇到这个简单的问题.首先,我必须创建一个包含5个联系人的文件,包括每个联系人的信息.然后我将不得不使用类将联系人放入列表中.然后,当从列表中选择任何联系人时,将显示新表单以及每个人的信息.以下是我到目前为止的代码:MAIN FORM
public Form1()
{
InitializeComponent();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
lstNames.Items.Clear();
}
private void btnGetInfo_Click(object sender, EventArgs e)
{
{
// Call methods
FileRead();
DisplayNameList();
}
}
private void FileRead()
{
try
{
StreamReader inputFile;
string line;
char[] deliminator = { ',' };
inputFile = File.OpenText("Accounts.txt");
//While loop to move through the entries.
while (!inputFile.EndOfStream)
{
//Use class
PersonEntry entry = new PersonEntry();
//Variable to hold line. …Run Code Online (Sandbox Code Playgroud) 据我所知,while循环可以这样做:
while (true) {
// run this code
if (condition satisfies)
break; // return;
}
Run Code Online (Sandbox Code Playgroud)
所以我接受了它并且我在下面输入了以下主要功能,我的问题是当我在满足条件(5或更多)后放置一个printf语句时,它会停止并且不显示任何内容,如果我什么也没放,它工作的break语句循环通过5个不同的客户!我错过了关于while循环的任何内容,或者这是它的工作方式吗?
int main ()
{
displayMenu();
while (true)
{
int gasType,gallonsAmount,carWashOption,customerAmount ;
float gasPrices[SIZE]={2.99,3.099,3.199,3.299}, washPrices[SIZE]=
{3.50,3.00,3.00,2.50}, perGallonRate,perWashRate,total;
float totalSum,totalGallonSum;
gasType = getGasType();
gallonsAmount = getGallons();
carWashOption = getCarWash();
perGallonRate = getGallonRate(gasPrices, gasType);
if (carWashOption == 'Y')
{
perWashRate = getWashRate( washPrices, gasType );
total = calcAmount(gallonsAmount, perGallonRate, perWashRate,&totalSum, &totalGallonSum);
}
else
{
perWashRate = 0;
total = calcAmount(gallonsAmount, perGallonRate, perWashRate,&totalSum, &totalGallonSum);
}
customerAmount++;// once we …Run Code Online (Sandbox Code Playgroud)