473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

help with array

hi all;

I need help with this simple program;

I was asked to declare an array of int type called value with 5 elements [ 2,4,6,8,10] . I want to use while structre to change the value of each element in the array to be the square of its original value. I made this code, but its not working,

# include < iostream >

int main()
{
int value []= { 2,4,6,8,10 };
int i=0 ,i++;

while ( i<5 )
{

std::cout<< value [i] * value [i]<<std::endl;
}

return 0;


}


thanks in advance
Oct 4 '06 #1
3 1702
The problem is in the statement
int i=0 ,i++;


The correct code is given below

# include < iostream >

int main()
{
int value []= { 2,4,6,8,10 };
int i=0;
while ( i<5 )
{
std::cout<< value [i] * value [i]<<std::endl;
i++;
}
return 0;
}

The increment should be inside the while statement.
Oct 4 '06 #2
thanks a million for your fast respond.
Oct 4 '06 #3
D_C
293 100+
Actually, he said he wanted to change each value in the array to it's square. The above program outputs the square value, but doesn't change it in the array.
Expand|Select|Wrap|Line Numbers
  1. # include < iostream >
  2.  
  3. int main()
  4. {
  5.   int value []= { 2,4,6,8,10 };
  6.   int i=0;
  7.   while ( i<5 )
  8.   {
  9.     value[i] *= value[i];
  10.     std::cout << value[i] <<std::endl;
  11.     i++;
  12.   }
  13. return 0;
  14. }
Oct 4 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Treetop | last post by:
I am creating a calendar with JavaScript. I want to be able to put date and time in an array and have a calendar display properly with 7 columns. I am stuck at this point. Any help would be...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
27
by: ruel loehr | last post by:
Hey guys, I am looking for some insight: Given two sorted arrays of integers A and B, where array B has enough extra room in it to hold the contents of both A and B. Merge array A and B...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.