arrays

hi!
can you help me with this program pls!
write a c++ prog that:
- declare an array named gamma of type char.
- declare an array named vowels of type char.
- prompt the user to input n characters in the array gamma.
- define a func named savevowels that determines and return the num of vowels letters in the gamma array and save them in the vowels array.

thank you!
i got a prob to get the chars from user ! how can i define an array without declaring its size??
Would you mind providing the code you've already written for it and what part or parts you are not understanding?
ive written this so far!it already showed errors with gamma array!
thanks in advance..

#include<iostream>
using namespace std;


void main()
{


char gamma[];
int i;
cout<<"insert characterst//insert -1 when you finish "<<endl;

while(i!=-1)
{

cin>>i;
gamma[]='i';


}

char vowels[]={'a','e','i','o','u'};
Last edited on
1) When posting code, please use code tags to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) char gamma[];

This is not legal. When you define an array, you need to specify the size of it.
prompt the user to input n characters in the array gamma.

Who decides the n? You?
If yes, then you know that both arrays need n elements.

It does sound like "yes", for there are no instructions to ask the n from the user.


1
2
int i;
cin >> i;

If you do ask for characters, then you should read characters and not integers.


that determines ... vowels letters in the gamma array and save them in the vowels array.

Sounds like "copies vowels (letters) from gamma to vowels (array)".
thanks, both of you!
i still just cant figure out the way i can define the array without declaring its size !!all the ways above didn't work! i do not know the size , the size will get declared when the user stops inserting the characters.. i'm still not sure about this ! ill really be grateful if you try to reexplain this part. like should i try the "dynamic allocation " thing to define the array ?
Are you certain that you must use a C++ array? If so then you need to declare an array that's big enough to hold the largest input that expect. For example:
char gamma[10000];
But this sort of programming is rightfully frowned upon. What if the user wants to enter 10008 characters instead of 10,000? This is how you create a security flaw called a "buffer overrun"

If allowed, you should use C++'s standard string class instead.

Can you post the exact text of the assignment? Small choices in wording are often significant to how you should solve the problem.
write a c++ program that:
- declares an array named gamma of type char.
- declares an array named vowels of type char.
- prompts the user to input n characters in the array gamma.
- defines a function named savevowels that determines and return the number of vowels [a,e,u,i,o] letters in the gamma array and save them in the vowels array.


that's the assignment text !
IMO these two are different scenarios:
the size will get declared when the user stops inserting the characters
- prompts the user to input n characters



Which prompt do you prefer:
"Give me 10 dollars."
"Give me as many dollars as you have."
Topic archived. No new replies allowed.