gpt4 book ai didi

c++ - 尝试使用 for 循环输出 10 行

转载 作者:行者123 更新时间:2023-11-27 22:59:29 24 4
gpt4 key购买 nike

在程序中输入数字时,我试图获得以下输出:

http://i.imgur.com/POIlhb2.png

但我只得到一行而不是全部十行。有人可以引导我完成这个吗?谢谢。我的代码如下:


#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<<"\t\t\t****************************************"<<endl;
cout<<"\t\t\t* *"<<endl;
cout<<"\t\t\t* *"<<endl;
cout<<"\t\t\t* Square-Cube Program *"<<endl;
cout<<"\t\t\t****************************************\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<<"\n\t\t\tT 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;
}

关于c++ - 尝试使用 for 循环输出 10 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29221828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com