tanderson
tanderson

Reputation: 1

Trying to output 10 lines using for loop

I'm trying to get the following output when entering a number into the program:

https://i.sstatic.net/mhjlR.jpg

But I only get one line instead of all ten. Can someone walk me through this? Thank you. My code below:


#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;
}

Upvotes: 0

Views: 68

Answers (1)

DigitalNinja
DigitalNinja

Reputation: 1098

I think you meant to do this:

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;
}

Upvotes: 4

Related Questions