我似乎无法弄清楚为什么这个while循环停止循环.在我移动一些代码之前,它做得很好.现在我得到了其他工作,它只是不循环.我也尝试过将一个bool设置为true并尝试让它循环而它是真的,直到用户点击4退出,在这种情况下它将把它变为false但是这不起作用.我也尝试在showMenu的函数中添加一个while循环但是也没有用.我知道它一定是简单的我无法抓住它.gggrrrr.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
enum transType { SETUP=1, DEPOSITE, WITHDRAW, EXIT};
int showMenu(double balance);
double transaction(double amount, double balance, transType trans);
int menuSwitch;
int quit=0;
int _tmain(int argc, _TCHAR* argv[]){
int amount=0,balance=0;
while(quit!=4){
showMenu(balance);
switch (menuSwitch){
case DEPOSITE:
cout<<"Enter the amount of deposit: ";
cin>>amount;
cout<<"Your current balance is: "<<transaction(amount,balance,DEPOSITE)<<endl<<endl;
break;
case WITHDRAW:
cout<<"Enter the amount of withdraw: ";
cin>>amount;
if(amount>balance){
cout<<"*** Insufficient funds."<<"Your current balance is: "<<transaction(amount,balance,WITHDRAW)<<endl<<endl;
}
else cout<<"Your current balance is: …Run Code Online (Sandbox Code Playgroud) var lastRecordedTime:Number = getTimer();
while(getTimer()>lastRecordedTime+10000)
{
}
Run Code Online (Sandbox Code Playgroud)
我想让我的游戏处于等待状态.我应该像这样使用while循环还是有更高效的方法呢?
我在编写代码时遇到问题,只要用户没有结束"退出",就会生成一个while循环请求用户输入.当我运行代码时,它只生成第一个提示问题"输入一个句子或一个短语:",然后在输入短语后它不会计算while语句.有谁知道我做错了什么?
问题是:"让程序让用户继续输入短语而不是每次都重新启动它会很好.为此,我们需要围绕当前代码的另一个循环.也就是说,当前循环将嵌套在里面新的循环.添加一个外部while循环,只要用户没有输入短语quit就会继续执行.修改提示以告诉用户输入短语或退出退出.注意所有的初始化count应该在while循环中(也就是说我们希望用户输入的每个新短语重新开始计数).你需要做的就是添加while语句(并考虑读取的位置以便循环正常工作)确保完成程序并在添加代码后正确缩进 - 使用嵌套循环时,内循环应缩进."
import java.util.Scanner;
public class Count
{
public static void main (String[] args)
{
String phrase; // A string of characters
int countBlank; // the number of blanks (spaces) in the phrase
int length; // the length of the phrase
char ch; // an individual character in the string
int countA, countE, countS, countT; // variables for counting the number of each letter
scan = new Scanner(System.in);
// Print a program header
System.out.println ();
System.out.println ("Character Counter"); …Run Code Online (Sandbox Code Playgroud) 正如标题所说,我应该使用
while(getchar() != '\n');
Run Code Online (Sandbox Code Playgroud)
每次我使用scanf?有人可以解释背后的逻辑
while(getchar() != '\n');
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在创建一个项目,我需要创建一个方法,创建两个不同的紫色斑点,这些斑点将在不同的程序中调用.这是我的代码:
public class PaintablePicture extends Picture
{
public PaintablePicture(String fileName)
{super(fileName);}
public void purpleSplotch(int x,int y)
{
int x=0;
int y=1;
while(x < x*2)
while(y < y*3)
{
Color purple = new Color(175, 0, 175);
Pixel pixRef;
pixRef= this.getPixel(x,y);
pixRef.setColor(purple);
}
return;
}
Run Code Online (Sandbox Code Playgroud)
在我调用它的其他程序中,我有:
FileChooser.pickMediaPath();
PaintablePicture pRef;
pRef = new PaintablePicture(FileChooser.pickAFile());
pRef.purpleSplotch(10,20);
pRef.explore();
Run Code Online (Sandbox Code Playgroud)
我必须做一个使用变量的while循环,以便制作splotches,我不明白帮助我,请得到"错误:重复局部变量x"
我看了这个,我几乎得到了它,但我有一个剩余的运行时错误.
我的代码如下:
while ((line = reader.ReadLine()) != null)
{
while (reader.Peek() != '\r')
{
datalinestream.Add(GetWord(reader));
}
LuceneDB.AddUpdateLuceneIndex(new MATS_Doc( datalinestream));
datalinestream.Clear();
}
Run Code Online (Sandbox Code Playgroud)
代码正在导入数据,但循环不会中断,并且由于以下原因而崩溃
"mscorlib.dll中发生了'System.OutOfMemoryException'类型的未处理异常"
外部while循环的适当中断条件是什么,以确保我读取整个文件并在结束时中断.我很难解决这个问题,因为我需要前进到下一行,我需要跳过电子表格中的第一行.任何帮助非常感谢.
*更新*
我清除字符串列表,因为我正在为lucene索引创建一个文档,它只有大约14个字段,我不希望列表变得太大.
我的getword代码
private string GetWord(TextReader inputdata)
{
String word = "";
while (inputdata.Peek() >= 0)
{
word += (char)inputdata.Read();
if ((word.Contains(";"))) break;
}
return word;
}
Run Code Online (Sandbox Code Playgroud) 我在解决这个问题时遇到了一些麻烦.我想循环遍历所有月份,而不是现在我的代码正在执行的十二次.任何人都可以帮助,还有一种更有效的循环这个功能的方法吗?
谢谢!
window.onload = function() {
getMonth();
};
function getMonth()
{
var x="",i=0;
var month=Array();
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";
while (i<12)
{
x=x + month + "<br/>";
i++;
}
document.getElementById("months").innerHTML=x;
}
Run Code Online (Sandbox Code Playgroud)
这是我的jsfiddle演示http://jsfiddle.net/priswiz/LqEE6/的链接
在这段代码中,我试图让用户输入一个int值(x),然后在下面的while循环中比较这个值:while(k <x).当我这样做时,我的程序崩溃了.
int main()
{
long int sum = 0;
long int i = 1;
long int j = 2;
long int k = 0;
int x = 0;
printf("This program will sum up all of the evenly valued terms from the
Fibionacci sequence, up until the\n user-specified highest term value.\n");
printf("Set this limit: ");
scanf("%d",x);
while(k < x)
{
k = i + j;
if(k%2==0)
sum +=k;
i = j;
j = k;
}
printf("The sum of all of …Run Code Online (Sandbox Code Playgroud) 这是错的吗?当Ran1,Ran2,Ran3都相同时,我想退出while循环.TNX
Random RandomNumber = new Random();
int Ran1 = RandomNumber.nextInt(4);
int Ran2 = RandomNumber.nextInt(4);
int Ran3 = RandomNumber.nextInt(4);
while (Ran1 != Ran2 && Ran1 != Ran3 && Ran2 != Ran3 ){
Ran1 = RandomNumber.nextInt(4);
Ran2 = RandomNumber.nextInt(4);
Ran3 = RandomNumber.nextInt(4);
System.out.print(Ran1);
System.out.print(" ");
System.out.print(Ran2);
System.out.print(" ");
System.out.println(Ran3);
Run Code Online (Sandbox Code Playgroud)
}
我有4个嵌套的while循环,它们看起来都类似于下面的那个
x = 0.0
while x <= 1.0:
ls_alloc[0] = x
x = x + 0.1
Run Code Online (Sandbox Code Playgroud)
我想要它做的是每次添加0.1到x,而它是<= 1.0我遇到的问题是它从来没有真正进入while循环 x = 1.0
我正在使用python 2.7
while-loop ×10
loops ×4
java ×3
c ×2
arrays ×1
buffer ×1
c# ×1
c++ ×1
character ×1
colors ×1
comparison ×1
counting ×1
function ×1
image ×1
javascript ×1
parameters ×1
python ×1
scanf ×1
streamreader ×1