for循环-C++Diamond控制台输出问题
for loop - C++ Diamond Console Output Issues
我正试图让我的for循环在给定用户特定的最大值和最小值的情况下输出一个菱形,甚至不允许输入。任何想法都将不胜感激。练习并没有我想象的那么顺利。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int rows, count;
cout<<"What is the width of the diamond (3 to 21, odd values only): ";
cin>>rows;
//Error checking
if(rows < 1 || rows > 25)
{
cout<<"Invalid. please enter an odd number from 1 to 25: ";
cin>>rows;
}
//Ascending
for (count = 1; count < rows; count += 1)
{
for (int rows = 0; rows < count; rows ++)
cout<<"*";
cout<<endl;
}
//Descending
for (count; count > 0; count -= 1)
{
for (int rows = 0; rows < count; rows ++)
cout<<"*";
cout<<endl;
}
cin.get();
cin.get();
return 0;
}
这执行目标的前半部分-:
for (int stars = 1; stars <= rows; stars+=2)
{
int padding = rows - stars;
for (int c = 0; c < padding/2; ++c)
cout<<" ";
for (int s = 0; s < stars; ++s)
cout<<"*";
cout<<endl;
}
相关文章:
- C++ 每次运行程序时我都会"nan"输出的问题
- 阶乘问题在 c++ 中给出错误的输出
- 数组为此合并排序函数提供了正确的输出,但向量给出了不正确的输出.出了什么问题?
- 代码输出随机符号,我不确定出了什么问题
- C++ 回文程序总是给出 0(假)作为输出问题;我的代码哪里有问题?
- 向量<对<双精度,双精度>>给出问题
- 函数以相反的顺序输出输入问题,并改进算法以解释相等的数字
- 服务器未收到UDP数据包,花费数小时试图找出问题所在
- 子输出出现在主进程使用 system() 调用它之前
- Linux 标准输出管道问题
- C++中的代码输出出现问题
- c++输出格式问题
- fmod 输出有问题(长双精度、长双精度)
- C++ 输出找出问题
- c++中的输出文件问题
- 嵌套 std::map 的输出存在问题
- 在成功运行10小时后,在发布模式下从windows应用程序中获得异常,如何检测出问题
- 日志文件输出的问题-字符串和c_str之间的差异- c++
- 关于反汇编输出的问题
- c++输出的问题