小编Tor*_*ell的帖子

while循环在C++中不循环

所以我昨天刚开始 C++,我有相当多的 java 经验,所以这就是原因,我尝试运行这段代码,由于某种原因 while 循环没有循环,我尝试将 if break 语句从 更改ask==falseask=false,这最终会导致无限循环,甚至不接受用户输入。

这是代码:

#include <iostream>
#include <math.h>
using namespace std;

int main(){
    double raduis;
    const double pi = 3.14;
    bool ask;
    
    while(true){
        cout << "Enter the raduis of the circle:"<< endl;
        cin >> raduis;
        double circ = 2*pi*raduis;
        double area = pi*pow(raduis,2);
        cout << "The Circumference of the circle is: "<< circ <<endl;
        cout << "The Area of the circle is: "<< area<<endl;
        cout <<"Would you like to …
Run Code Online (Sandbox Code Playgroud)

c++ loops if-statement while-loop

2
推荐指数
1
解决办法
211
查看次数

标签 统计

c++ ×1

if-statement ×1

loops ×1

while-loop ×1