我刚刚开始学习C编程语言.我写了这段简单的代码,将美元兑换成欧元.唯一的问题是,一旦输入美元输入,程序就会挂起.我正在使用while循环来询问用户是否要重做操作,所以我的猜测是代码的语法导致了一个永恒的循环,但我不确定.
这是我的代码:
#include<stdio.h>
#define conv 0.787033 //conversion factor of USD to Euro found www.ex.com//
int main(void)
{
float USD, EURO;
char cont = 'y';
while (cont == 'Y' || cont == 'y')
{
printf("Please enter the amount of United States ");
printf("Dollars you wish to convert to Euros\n");
scanf("%f\n", &USD);
EURO = USD * conv;
printf("%.2f dollars is %.2f Euros\n", USD, EURO);
printf("Do you wish to convert another dollar amount (Y/N)?\n");
scanf("%c\n", &cont);
}
return(0);
}
Run Code Online (Sandbox Code Playgroud) 嘿家伙......再次新手:)我正在组合一个计算三角形或正方形区域的程序,然后提示用户是否希望计算另一个.我已经得到了代码,它将计算任一形状的区域,但不会继续其余的代码.例如,选择方形,计算面积,然后返回到方形边的提示.我假设它永远是while循环,但不知道如何阻止循环无休止地继续.
继承我的代码:
#include<stdio.h>
#include<math.h>
int main(void)
{
float sq_side, tri_base, tri_height, Area;
char shape, cont = 'Y';
printf("Please select the type of shape you desire to calculate the area for:\n");
printf(" \n");
printf(" Square = S Triangle = T \n");
printf(" ------- x \n");
printf(" : : x x \n");
printf(" : : x x \n");
printf(" ------- xxxxxxx \n");
printf(" \n");
printf("Please select either S or T:");
scanf("%c", &shape);
while (cont != 'n' && cont != 'N')
if (shape …Run Code Online (Sandbox Code Playgroud) 我有一个简单的m文件,我已创建为递归函数:
function[velocity] = terminal(m,c,t,vi)
%inputs:
% m = mass
% c = coeffcient of drag
% t = time
% vi = initial velocity
if t==18, velocity = vi+(9.8-c/m*(vi))*2;
return
end
velocity = vi+(9.8-c/m*(vi))*2;
velocity %used to print out velocity for debugging
terminal(m,c,t+2,velocity);
end
Run Code Online (Sandbox Code Playgroud)
正确地计算速度,因为它打印出每次递归.但是,最后返回的"ans"是递归的第一个计算值.我的问题是如何递归地正确设置matlab函数?或者它可以完成,并且使用循环更好吗?
我正在尝试创建一个文件作为我的扩展程序中的一个命令的一部分,但似乎无法正确设置。
let wsedit = new vscode.WorkspaceEdit();
const file_path = vscode.Uri.file(value + '/' + value + '.md');
vscode.window.showInformationMessage(file_path.toString());
wsedit.createFile(file_path, {ignoreIfExists: true});
vscode.workspace.applyEdit(wsedit);
vscode.window.showInformationMessage('Created a new file: ' value + '/' + value + '.md);
Run Code Online (Sandbox Code Playgroud)
value是用户输入的字符串。代码执行,但据我所知,没有创建文件。如何正确创建文件?
我有一个对象数组,我想根据对象的某个值(即self.example.value)进行排序.我创建了多个可变数组:
NSMutableArray *array1, *array2, *array3 = [[NSMutableArray alloc] initWithObjects: nil];
然后使用for循环遍历原始数组.如果对象匹配条件(self.example.value == someValue).我将对象添加到上面创建的一个新数组中.但是,当我稍后开始使用数组时,我注意到它们是空的.使用调试器我注意到以下内容:
for (customClass *object in arrayOfObject){ //starting here the debugger has NONE of the arrays created above
if (object.value == someValue){//after performing this line, the debugger shows array1 in memory BUT nothing in it EVEN if the 'if' statement isn't TRUE.
[array1 addobject:object];
} else if (object.value == someOtherValue){//after performing this line, the debugger shows array2 in memory BUT nothing in it EVEN if …Run Code Online (Sandbox Code Playgroud) 假设我有一个空数组,如下所示:
s=[];
Run Code Online (Sandbox Code Playgroud)
比方说我们有以下循环:
for j=1:2
for i=1:10
if a(i,j)>0
...
end
end
end
Run Code Online (Sandbox Code Playgroud)
而不是...,我想添加元素s.你是如何在MatLab中做到的?