i am supposed which accepts a five-digit integer value. my program is then to output the digits, one per line. Each line of output should contain the digit value, its square and its cube.

Once I have the program running correctly, modify the program so that it will process as many values as the user requests. The program should BEGIN by prompting the user for the number of values to be processed.

I am having trouble with the output.
the output should look like this:

How many values will you enter: 3
enter a value: 12345
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
enter a value: 11223
1 1 1
1 1 1
2 4 8
2 4 8
3 9 27
enter a value: 33322
3 9 27
3 9 27
3 9 27
2 4 8
2 4 8

this is what i got so far:

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
   
using namespace std;

const int size = 5;
int main()
{
	int trials, nums[size], square, cube;
	cout << "please enter number of values to be processed:\n";
	cin >> trials;

	cout << "please enter" << trials <<  "values:\n";
	for (int trial = 1; trial <= trials; trial++)
	{
		for (int index = 0; index < size; index++)
		{

			cin >> nums[size];
			nums [index] = nums [index] *nums [index];
	
	
	
		cout << nums[size] << nums[index];
	}
	
	}
	return 0;
}

Edited 6 Years Ago by Nick Evan: Added code-tags

#include<iostream.h>
#include<conio.h>
#include<math.h>
int main()
{
    long int x,array[10];
    cout<<"how many value you enter: ";
    int trials,i=0,y;
    cin>>trials;
    while(i<trials)
    {
                   int count=0;
                   cout<<endl<<"Enter a value:";
                   cin>>x;
                   while(x!=0)
                   {
                              array[++count]=x%10;
                              x=x/10;
                              }
                   for(int j=count;j>=1;j--)
                   {
                           cout<<array[j]<<"\t"<<pow(array[j],2)<<"\t"<<pow(array[j],3);
                           cout<<endl;
                           }
                   i++;
         }
    system("PAUSE");
    return 0;
}

Edited 6 Years Ago by Nick Evan: Added code-tags

You can try this:

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int y=0;	
	cout<<"Number of times";
	cin>>y;
	for(int n=0;n<y;n++)
	{
		char str[5];
		cout<<"Enter 5 nos.: ";
		cin>>str;
		if(!str)
			return 0;
		for (int count=0;count<5;count++)
		{
			cout<<pow(str[count]-'0',1)<<" "<<pow(str[count]-'0',2)<<" "<<pow(str[count]-'0',3)<<endl;
		}
	}
return 0;
}

Thank you guys for your help! I really appreciate it. could you be kind to explain the steps in details please? I have few questions that aren't really clear to me.

#include "stdafx.h"
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    long int x,array[10];
    cout<<"how many value you enter: ";
    int trials,i=0,y;
    cin>>trials;
    while(i<trials)
    {
       int count=0;
       cout<<endl<<"Enter a value:";
       cin>>x;
       while(x!=0)
       {
			array[++count]=x%10; // what is this line doing to the x?
            x=x/10; // why does x have to be divided by 10?
       }
       for(int j=count;j>=1;j--)
       {
			cout<<array[j]<<"\t"<<pow(array[j],2.0)<<"\t"<<pow(array[j],3.0);
            cout<<endl;
       }
            i++;
         }
    system("PAUSE");  // why are you using system("PAUSE");
    return 0;
}
This article has been dead for over six months. Start a new discussion instead.