如何使用用户输入的变量终止for循环 [英] How do I terminate a for loop with a variable the user inputs

查看:132
本文介绍了如何使用用户输入的变量终止for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,当用户为K输入一个数字时,我试图退出,如何用这个数字终止循环?



 for(int K = 0; K< = 9; K ++)
{
cout<< 输入卡路里,脂肪,蛋白质和其他的量<< ENDL;
cout<< 卡路里:<< ENDL;
cin>> C;
cout<< 脂肪:<< ENDL;
cin>> F;
cout<< 蛋白质:<< ENDL;
cin>> P:
cout<< 其他:<< ENDL;
cin>> O;
}





我的尝试:



我尝试过使用不同的循环,似乎没有任何工作

解决方案

引用:

我有这段代码,当用户为K输入一个数字时,我试图退出,如何用这个数字终止循环?



自用户没有为 K 输入任何内容,我担心我们无法帮助您。

您需要优化详细信息你试图做什么。



对于我所看到的,循环的可以完全删除。


I have this piece of code that I am trying to exit when the user inputs a number for K, how to i terminate the loop with that number?

for ( int K=0; K<=9; K++)
   {
    cout << "Enter the amount of Calories, Fats, Proteins & Other" << endl;
    cout << "Calories:" << endl;
        cin >> C;
    cout << "Fat:" << endl;
        cin >> F;
    cout << "Protein:" << endl;
        cin >> P;
    cout << "Other:" << endl;
        cin >> O;
    }



What I have tried:

I have tried using different loops and nothing seems to work

解决方案

Quote:

I have this piece of code that I am trying to exit when the user inputs a number for K, how to i terminate the loop with that number?


Since the user do not input anything for K, I fear we can't help you on this.
You need to refine the question with details on what you try to do.

For what I see, the for loop can completely be removed.


这篇关于如何使用用户输入的变量终止for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆