Function issue

This is a discussion on Function issue within the C++ Programming forums, part of the General Programming Boards category; Hello, Yes I have question I am trying to call a function that would allow me to use the string ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    10

    Function issue

    Hello,

    Yes I have question I am trying to call a function that would allow me to use the string I entered in the cin.getline. Well basically here is the problem:

    -Function 2: (Accept three arguments: an array and two characters, and return no value)
    This function will accept an array containing the string and two characters. It will scan for the first character and when it finds the character, it will substitute the first character with the second character. Prompt for the character to be scanned and the character to be substituted in main() and pass those into the function.

    I have already done function 1, I just need to do function 2 but here is the program hat I have written don there are some errors though becuase I was trying to get the first function to pass to the next function.

    insert
    Code:
    #include <iostream>
    using namespace std;
     
    
    char Menu();
    void insrt_ch(char[], char , char); 
    //int (char*[], char);
    int main()
    
    {
    
    char Twinkle[80] = {' '};
    char select = ' ';
    char Sub_char = 'A';
    char count = 'B';
    char cont = 'Z';
    cout <<"Please enter a string: ";
    cin.getline(Twinkle, 80); 
    cout <<"\n";
    
    
    
    	cout << "Welcome to the string program ! \n";
    	cout << "=============================== \n";
    	cout << "A - Substitute Character \n";
    	cout << "B - Count Character \n";
    	cin >>select;
    	if(select != 'A')
    	{
    		cout << "Invalid selection! Please re-enter!";
    		cin >> select;
    	}
    
    	
    	
    	
    
    	void insrt_ch(char String_1[80], char select, char Next) 
    	
    	{	
    		char character = ' ';
    		char sub = ' ';
    		int i = 0;
    
    
    		switch(select)
    		{
    		case 'A':
    		case 'a':
    			{
    				cout << "Please enter the character to be scanned: ";
    				cin >> character;
    				cout << "Please enter the character to be substituted: ";
    				cin >> sub;
    				insrt_ch(char String_1[80], char select, char Next);
    
    				while(String_1[i] != '\0')
    				{
    				cout << String_1[i];
    				++i;
    				
    				}
    			break;
    		default: cout << endl << endl;		
    		break; 
    			}
    		}
    
    			while(select != 'Z');
    	
    	system("pause");
    	return 0;
    		}
    If you have any other questions or concern please let me know and thank you

  2. #2
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144
    Code:
    	cin >>select;
    	if(select != 'A')
    	{
    		cout << "Invalid selection! Please re-enter!";
    		cin >> select;
    	}
    This isn't going to work. You need a while staement . This "if statement" is only going to work the first pass through. The second select will be whatever is input.

    Youa also need to put the
    Code:
    void insrt_ch(char String_1[80], char select, char Next)
    outside the main() function. And you have to 'call' it from main().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21