尝试使用for循环输出10行
Trying to output 10 lines using for loop
在程序中输入数字时,我试图获得以下输出:
https://i.stack.imgur.com/mhjlR.jpg
但我只得到一行而不是全部十行。有人能带我走过这个吗?非常感谢。我下面的代码:
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
char ans='y';
int num = 0;
while (ans=='y' || ans=='Y')
{
system("cls");
system("color f0");
cout<<"ttt****************************************"<<endl;
cout<<"ttt* *"<<endl;
cout<<"ttt* *"<<endl;
cout<<"ttt* Square-Cube Program *"<<endl;
cout<<"ttt****************************************n"<<endl;
cout<<"Please enter a number to square,cube, and raise to the 4th power: ";
cin>>num;
cout<<"t"<<"Number"<<"t"<<"Square"<<"t"<<"Cube"<<"t"<<"4th Power"<<endl;
cout<<"t"<<"------"<<"t"<<"------"<<"t"<<"----"<<"t"<<"---------"<<endl;
for(int num=0; num<100; num++,num+=5){
cout<<"t"<<num<<"t"<<pow(num,2.0)<<"t"<<pow(num,3.0)<<"t"<<pow(num,4.0)<<endl;
cout<<"Would you like to continue (Y or N)? ";
cin>>ans;
}
cout<<"ntttT H A N K Y O U"<<endl;
system("pause");
return 0;
}
我想你是想这么做的:
for(int i=0; i<10; i++)
{
cout<<"t"<<num<<"t"<<pow(num,2.0)<<"t"<<pow(num,3.0)<<"t"<<pow(num,4.0)<<endl;
num+=5;
}
相关文章:
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 如何读取单个字符并在输入两个字符序列时输出? 使用 while 循环和C++
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 而循环:简单的除法程序输出零,不明白为什么
- 为什么即使使用 for 循环遍历我的向量,它也没有输出到控制台?(C++)
- 如何在 c++ 中使用 for 循环输出矢量中的所有对象
- 在循环输出中重用矢量 "Killed" 在几次迭代后
- C++ 嵌套循环输出不正确
- 为什么这个 while 循环输出非常奇怪的东西
- 为什么当用户输入除整数之外的任何内容时,我的程序会无限循环输出?C++
- 从 if 循环输出的数字错误
- 尝试使用for循环输出10行
- 对于循环输出问题
- C++:如何将数据从迭代循环输出到列中
- 了解循环输出
- C++:循环输出多维数组
- 如何使用嵌套的for循环输出2D字符数组
- 如何循环输出,以便显示文本文件中的所有结果?
- c++嵌套循环输出结果