我这几天正在学习QT,我想测试do while循环,实际登录正常工作,但在QT中应用程序冻结..我已经定义了randnum并在头文件中猜测(公共)
void MainWindow::on_pushButton_clicked()
{
srand (time(NULL));
randnum = rand() % 10 +1;
do {
guess = ui->spinBox->value();
if (guess < randnum)
{
ui->label->setText("try something big");
}
else if (guess > randnum)
{
ui->label->setText("try something small");
}
else
ui->label->setText("YAY?");
} while (guess != randnum);
}
Run Code Online (Sandbox Code Playgroud)
请告诉我如何找到冻结的原因..谢谢!
在某些情况下,我们可以互换使用while循环或do-while循环.我的一位朋友告诉我,这种情况我们应该使用do-while循环.因为它比同时更快.任何人都可以给我证明吗?
我正在查看教科书中的一些C代码,它包括这些代码
...
lastsec = get_seconds();
sec0 = get_seconds(); while (sec0 == lastsec);
...
Run Code Online (Sandbox Code Playgroud)
看起来很像do在第二行的末尾缺少 - 但无论如何代码它仍然应该编译.
我正在摸索着这个循环如何不会while (sec0 == lastsec);直到时间结束 - 假设get_seconds()没有增加......
这本书是计算机体系结构:定量方法,第五版. 这是第134页的代码.
嘿伙计这是我的代码,它正在做的是循环,但它假设要做的是如果用户键入借用然后它将询问用户它做了多少但然后他们输入一个数字,它将再次问他们你想借还是卖,它是无限循环的.
case 3:
do{
System.out.println("What would you like to do? Please type borrow to borrow money or sell to sell assets: ");
b = scan.nextLine().toLowerCase();
if(b.equals("borrow")){
System.out.print("how much would you like to borrow Remmber if you go over 50000 debt its game over.");
try {
input = scan.nextInt();
} catch (Exception e) {
System.err.println("That is not a number!!");
}
account.setdebt(account.getDebt() + input);
account.setBalance(account.getBalance() + input);
System.out.println("Your new Balance is " + account.getBalance());
}
else if(b.equals("sell")){
sellA();
}else{
System.out.println("You didn't input …Run Code Online (Sandbox Code Playgroud) 我正在制作一个小程序,将"你是一个成年人吗?"这个问题的答案作为输入.像这样的角色:
bool adult() {
char answer;
do {
printf("Are you an adult? [y/n]\n");
answer = getchar();
} while (!(answer == 'y' || answer == 'n'));
return (answer == 'y');
}
Run Code Online (Sandbox Code Playgroud)
我的目标是,如果答案既不是y,那么问题应该重复.但这似乎有一个错误:
当我回答其他内容(y或n)时,问题会被打印两次:
你是成年人吗?你是成年人吗?你是成年人吗?...
为什么会这样?另外,我尝试使用scanf而不是getchar的相同方法,但是存在相同的错误.对于这种程序,我应该使用scanf或getchar吗?为什么?
谢谢!
我期待在do..while()循环结束时做一个多OR条件,我不确定我是否正确行事.
我现在所拥有的如下:
do
{
(Insert code here)
}while(x != ('a' || 'e' || 'i' || 'o' || 'u');
Run Code Online (Sandbox Code Playgroud)
这会起作用还是应该以不同的方式写出来?
我编写了这个程序,为用户提供所有急性三角形解决方案,当它们给出最小值和最大值时.它正常工作,除了似乎解决方案不包括循环的第一次迭代(例如,min = 1和max = 45,(1,1,1)不包括在解决方案中).怎么解决这个问题?我认为问题在于我的while循环的a值,但是当我将其更改为for循环时,问题仍然存在.我怎么能包含这些第一个值?
if (c >= dmin) {
c = dmin;
do {
++c;
for (b = dmin; b < dmax; b++) {
a = dmin;
while (a < dmax) {
a = a + 1;
if (a * a + b * b - c == c * c) {
if (((a + b) > c) && ((b + c) > a) && ((c + a) > b)) {
printf("(%d, %d, %d)", a, b, c);
}
} …Run Code Online (Sandbox Code Playgroud) 我想问用户(使用Scanner)他希望程序循环多少次.我需要使用do-while循环语句来执行此操作,但每当我输入我希望它循环的次数时,它只会从我放入的值中减去它,然后重复该数量.
例如,我输入4,程序重复16次而不是4次.
这是我的计划:
System.out.println("Enter range");
int y = input.nextInt();
int x = 10;
do {
System.out.print("value of x : " + x );
x++;
y++;
System.out.print("\n");
} while(y < 20);
Run Code Online (Sandbox Code Playgroud)
我的问题在哪里?
我是Haskell的新手,我已经做了好几个月了,如果有人愿意帮助我,我会很高兴的!我试图让这个程序与do while循环一起工作.
我有这个while语句,可以运行这个阶乘程序"x = 4; y = 1;而!(x == 0)do(y = y*x; x = x - 1)"给我输出"[ ("x",整数0),("y",整数24)]".该计划如下:
whilestatement :: Parser Com
whilestatement =
do
symbol "while"
b <- bexpr
symbol "do"
s <- com
return (While b s)
Run Code Online (Sandbox Code Playgroud)
并且任务是制作一个do while语句,该语句可以运行这个阶乘程序"x = 4; y = 1; do(y = y*x; x = x - 1)而!(x == 0)".我所做的是我在while语句中做了一些修改.我更改了这部分只是交换了符号"do"和符号"while":
whilestatement :: Parser Com
whilestatement =
do
symbol "do"
s <- com
symbol "while"
b <- bexpr
return (While b s)
Run Code Online (Sandbox Code Playgroud)
程序运行并提供相同的输出.但这是做出while语句的正确方法,还是可以帮助我如何使while while语句做while语句.谢谢
我有一个如下的测试文件。(但实际文件有1000多行和许多列)
apple,2
mango,5
coconut,10
Run Code Online (Sandbox Code Playgroud)
我要按以下方式打印此文件。
I have apple and the count is 2
I have mango and the count is 5
I have coconut and the count is 10
Run Code Online (Sandbox Code Playgroud)
我尝试while read line使用awk -F ',' '{print $1}',但即时通讯未获得实际输出。有人可以帮我吗?