cplusplus.com
C++ : Forum : Beginners : Sting manipulation
 
cplusplus.com
Information
Documentation
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs


post Sting manipulation

studentm (9)
In my homework, I need to create a program that allows the user to enter a password. The the the program needs to change all vowels (A,E,I,O, and U) in the orginal password into the letter X. All numbers in the password should be replaced with the letter Z. And the orginal password should be reversed. This is what I have so far any help is appricated. Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;


int main()
{
	//delcare variables
	string oldPassword = "";
	int numChars= 0,
	
	
	//get password
	cout << "Enter password: " << endl;
	getline(cin, oldPassword);
	
	//convert password to lowercase
	transform(oldPassword.begin(), oldPassword.end(),
			  oldPassword.begin(), tolower);
	
	//determine the number of characters
	numChars = static_cast<int> (oldPassword.length());


	if (currentChar == "0" || currentChar == "1" || currentChar == "2" ||  currentChar == "3" || currentChar == "4" || currentChar == "5" || currentChar == "6" || currentChar == "7" || currentChar == "8" || currentChar == "9" )
	
	
			
	


	return 0;
}	//end of main function 
Last edited on
Bazzy (6258)
if (currentChar == "0" ...
1) A char literal is represented by single quotes: '0'
2) currentChar wasn't declared
3) You whould need to place this in a loop


Please use [code][/code] tags
Duoas (5977)
You can use the isdigit() function to determine if the character is in '0'..'9'.
I recommend you write yourself a function called isvowel() that takes a char as argument and returns whether or not it is a vowel.

As a matter of procedure, did your original assignment ask you to convert all letters to lowercase?

[edit] BTW, if you want to use isdigit() and tolower(), you should #include <cctype> .
Last edited on
Topic archived. No new replies allowed.