1.

Solve : C++ programing?

Answer»

I can't FIGURE out how to write this program.

Write a program that prompts the user to enter four integers and reads all four values with a single scanf statement. Write statements to find the square of each value. Print the values and their squares in a labeled aligned as in the example shown below:
Number Square
5 25
10 100
15 225
20 400Couldn't you just store those numbers in variables? Then use those variables in the MATH operation? It seems a beginners homework??Still that seems what he should do, even from a point of view from a person that has no real SOLD codeing experince. Not that I havent just things LIKE this an such. But I'm working at it.This is C# INSTEAD of C++ but the logic is the same, just substitute the syntax for whatever C++ uses.

static void Main(string[] args)
{
int[] square = new int[4];
int[] total = new int[4];

for (int i = 0; i < square.Length; i++)
{
Console.Write("Enter an integer: ");
square = Convert.ToInt32(Console.ReadLine());
}

for (int j = 0; j < square.Length; j++)
{
total[j] = square[j] * square[j];
}

Console.WriteLine("Number\t Square");

for (int k = 0; k < square.Length; k++)
{
Console.WriteLine(" {0}\t {1}", square[k], total[k]);
}

}
Did you succeed in converting the C# code to C++?
#include
#include
using namespace std;
int main()
{
int num[4];
for(int n=0;n<4;n++)
{
cout<<"enter a number\n";
cin>>num[n];
}
for(int z=0;z<4;z++)
{
cout<)<<endl;
}

this should work
I think your missing a } but not sure I did java so I could be wrong here.yes, there is a missing }I thought so not sure if it was throwing him off or not havent done java in a while.



Discussion

No Comment Found