Hi everyone. Iam a beginning C++ student having trouble with a simple one column char. aray. what I'm trying to do is : display the value of the seventh element of chaacter array f. Wich shoud b 6 if a=0. Please help. Below is my code, so far:
[
#include <iostream>
#include <iomanip>

using namespace std;

int value;
int main()
{
const char(10);
char chABCD[10] = { 'a', 'b', 'c', 'd', 'e', 'f' };
for ( int a = 0; a < 10; a++)
a=(0);
cout << value('f') << endl;]

Recommended Answers

All 12 Replies

Hmm looks like your basics are a bit err.. shaky. You got most of the syntax there wrong. Why not revist the basics by learning something about C++ with good books. Some tuts here

I think maybe u looking for something like this:

#include <iostream>
using namespace std ;

int main (void)
{
    const int size = 6 ;
    char my_array [size] =  {'a', 'b', 'c', 'd', 'e', 'f' } ;
    cout << "\nThe value of 6th element is " << my_array [5] ;
    cin.get ();
    return 0 ;
}

Hope it helped, bye.

#include <iostream>

using namespace std;

int main()
{ 
     char value[10] = { 'a', 'b', 'c', 'd', 'e', 'f','g','h','i','j'};
     for ( int a = 0; a < 10; a++)
         cout << value[a] << endl;
}

Next time post your code in [inlinecode][/inlincode] tags.

I to don't entirly get what you are trying to do. So I altered your code to display al array elements. To display only the 7th element will be(untested):

#include <iostream>

using namespace std;

int main()
{
    char array[10] = {'a','b','c','d','e','f','g','h','i','j'};
    cout << "The value is: " << array[7] << "." << flush;
}

Go over the basics of C++ again, you made some pretty big mistakes in those.

Edit: to late

Thanks. All help is appreciated. This stuff is just not sinking in. I have scanned the directions out of the book,if you have any other ideas. Thanks again.

4.8
.
Write C++ statements to accomplish each of the following:
a) Display the value of the seventh element of character array f.
b) Input a value into element 4 of single-subscripted floating-point array b.
c) Initialize each of the 5 elements of single-subscripted integer array g to 8.
d) Total and print the elements of floating-point array c of 100 elements.
e) Copy array a into the first portion of array b. Assume double a[ 11], b[ 34];
f) Determine and print the smallest and largest values contained in 99-element floating-point array w.

4.8
.
Write C++ statements to accomplish each of the following:
a) Display the value of the seventh element of character array f.
b) Input a value into element 4 of single-subscripted floating-point array b.
c) Initialize each of the 5 elements of single-subscripted integer array g to 8.
d) Total and print the elements of floating-point array c of 100 elements.
e) Copy array a into the first portion of array b. Assume double a[ 11], b[ 34];
f) Determine and print the smallest and largest values contained in 99-element floating-point array w.

Well, that's an pretty simple asignment and if you have payed attention in class/course will you be able to figure it out. If you need any help with it then ask it here again!

Well, that's an pretty simple asignment and if you have payed attention in class/course will you be able to figure it out. If you need any help with it then ask it here again!

Having trouble with step "c" can you help me out?

c) Initialize each of the 5 elements of single-subscripted integer array g to 8.

What have you attempted till now, post it here so that we can set your logic right and make you understand things more clearly.


so far . I'm just missing something,but don't know what. Thanks

{ char array [10] = {'a','b','c','d','e','f','g','h','i','j'};
cout << "The value is: " << array[3] << "." << endl;

for (char array[10] = 8; array < 9; array[10] 5 ==)
array[10] = 8;

4.8
.
Write C++ statements to accomplish each of the following:
a) Display the value of the seventh element of character array f.
b) Input a value into element 4 of single-subscripted floating-point array b.
c) Initialize each of the 5 elements of single-subscripted integer array g to 8.
d) Total and print the elements of floating-point array c of 100 elements.
e) Copy array a into the first portion of array b. Assume double a[ 11], b[ 34];
f) Determine and print the smallest and largest values contained in 99-element floating-point array w.

All the parts here require you to create new arrays and i think are not dependent on each other.

Part C requires you to create an INTEGER array "g" and initialize all the five elements to 8. As i can see from your attempt you still havent completely grasped the syntax so you need to work on it.

Part d requires you to create an FLOATING POINT array "c" of 100 elements and add all the elements up.

Part e requires copying value from array "a" to array "b" with the given indices.

Part f require you to find the smallest and largest number in the array having 100 floating point numbers and is named "w".

As far as part c is concerned i will give you small snippet and you can do the rest of the parts yourself.

#include <iostream>
using namespace std ;

int main (void)
{  
   int g [5], counter;
   for (counter = 0; counter < 5; ++counter)
      g[counter] = 8 ;

   cin.get () ;
   return 0 ;
}

HOpe it helped, bye.

As far as part c is concerned i will give you small snippet and you can do the rest of the parts yourself.

#include <iostream>
using namespace std ;

int main (void)
{  
   int g [5], counter;
   for (counter = 0; counter < 5; ++counter)
      g[counter] = 8 ;

   cin.get () ;
   return 0 ;
}

HOpe it helped, bye.

I don't read c that way.

c) Initialize each of the 5 elements of single-subscripted integer array g to 8.

To me that's a single statement. Define c and load values during the definition -- similar to the way array was handled.

I love instructions that are vague and interpretable... :confused:

Hmm... yes there is yet another way of looking at that (theres always a second perspective).

c) Initialize each of the 5 elements of single-subscripted integer array g to 8.

Yes it can be what you say taking into consideration the level of the previous questions but can also be what i considered seeing the level of the questions which follow.

I hate such kind of questions, makes me remind of the customer requirement gathering phase of software development, they are so vague. :D

i want to know about the templates in detail
pls sennd me about this

Create a new thread for your questions. Dont hijack other peoples threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.