Loops 如何结束此循环/逻辑结束伪代码
我正在编写一个伪代码程序来读取客户记录,确定他们的帐户类型,然后在最后输出他们的姓名和欠款。我写了一个程序(几乎完成了),我只是不知道如何循环它,直到没有更多的记录了。你们能帮帮我吗?我最后的输出应该是客户姓名和欠款。谢谢Loops 如何结束此循环/逻辑结束伪代码,loops,logic,pseudocode,do-while,records,Loops,Logic,Pseudocode,Do While,Records,我正在编写一个伪代码程序来读取客户记录,确定他们的帐户类型,然后在最后输出他们的姓名和欠款。我写了一个程序(几乎完成了),我只是不知道如何循环它,直到没有更多的记录了。你们能帮帮我吗?我最后的输出应该是客户姓名和欠款。谢谢 read_customer_record get num_of_records get customer_name get account_type get num_basic_channels get num_premium_channels calculate_
read_customer_record
get num_of_records
get customer_name
get account_type
get num_basic_channels
get num_premium_channels
calculate_rate (calcR)
calculate_totals (calcT)
output(outp)
END
Calculate_rate (calcR)
IF account_type = personal
Basic_rateP = $5
Pre_rateP = $10
ELSE
Basic_rateB = $7.50
Pre_rateB = $12.50
END
Calculate_totals (calcT, calcR)
IF account_type = personal
total = (num_basic_channels * Basic_rateP) + (num_premium_channels * Pre_rateP)
ELSE
total = (num_basic_channels * Basic_rateB) + (num_premium_channels * Pre_rateB)
END
output (
您可以这样做:
>>打印客户名称和欠款金额,直到客户名称不等于空
<如果我用C++编写代码,它看起来会像这样。
for(i=0;CustomerName[i]!=NULL;i++) //Loop till there is some Customer Name exists
{
cout<<CustomerName[i]<<"\t"<<AmountOwed[i]; //Printing out the Data
}
for(i=0;CustomerName[i]!=NULL;i++)//循环直到存在某个客户名称
{
cout我认为你只需要围绕你的主要日常工作写一个WHILE语句。方法取决于你从哪里读取客户记录
案例1:在许多上下文中,您只能通过尝试读取结束来判断您已经完成了对输入流的处理。在这种情况下,您的伪代码可能如下所示:
read_customer_record
while the previous read succeeded
get num_of_records
get customer_name
get account_type
get num_basic_channels
get num_premium_channels
calculate_rate (calcR)
calculate_totals (calcT)
output(outp)
read_customer_record
end
while there are more customer records to process
read_customer_record
get num_of_records
get customer_name
get account_type
get num_basic_channels
get num_premium_channels
calculate_rate (calcR)
calculate_totals (calcT)
output(outp)
end
案例2:在其他上下文中,您可以在读取之前判断输入流中是否还有剩余的内容需要读取。在这种情况下,您的伪代码可能如下所示:
read_customer_record
while the previous read succeeded
get num_of_records
get customer_name
get account_type
get num_basic_channels
get num_premium_channels
calculate_rate (calcR)
calculate_totals (calcT)
output(outp)
read_customer_record
end
while there are more customer records to process
read_customer_record
get num_of_records
get customer_name
get account_type
get num_basic_channels
get num_premium_channels
calculate_rate (calcR)
calculate_totals (calcT)
output(outp)
end
那么,我在哪里可以启动类似的for循环呢?我的其余逻辑有意义吗?我编写了用于打印结果的循环。如果您想对记录进行一些计算,可以简单地使用数组。例如total[I]。是的,您的逻辑有意义,但在处理If-Else语句时,请确保小心地使用括号}。