473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Function issue

9 New Member
I think there is something wrong with my program I got this fom my TA and I think he kind of messed up somewhere I just don't know what to change:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int String(char[]);
  5. char Menu();
  6. void Second(char, char, char[],int);
  7.  
  8. int main()
  9.  
  10. {
  11.  
  12. char Twinkle[80] = {' '};
  13. char select = ' ';
  14. char Sub_char = 'A';
  15. char count = 'B';
  16. char cont = 'Z';
  17. cout <<"Please enter a string: ";
  18. cin.getline(Twinkle, 80); 
  19. cout <<"\n";
  20.  
  21.     do
  22.     {
  23.     select = Menu();
  24.  
  25.     if(select != 'A')
  26.     {
  27.     cout << "Invalid selection ! Please re-enter !\n";
  28.     cin >> select;
  29.     }
  30.  
  31.  
  32.  
  33.         char String_1[80] = {' '};
  34.         char character = ' ';
  35.         char sub = ' ';
  36.         int i = 0;
  37.         switch(select)
  38.         {
  39.         case 'A':
  40.         case 'a':
  41.             {
  42.                 cout << "Please enter the character to be scanned: ";
  43.                 cin >> character;
  44.                 cout << "Please enter the character to be substituted: ";
  45.                 cin >> sub;
  46.                 Second(character, sub, String_1, 80);            
  47.  
  48.                 while(String_1[i] != '\0')
  49.                 {
  50.                 cout << String_1[i];
  51.                 ++i;
  52.             }
  53.             }
  54.  
  55.     }
  56.     while(select != 'Z');
  57.  
  58.     system("pause");
  59.     return 0;
  60.     }
  61. }
  62.  
  63. char Menu()
  64. {
  65.     cout << "Welcome to the string program ! \n";
  66.     cout << "=============================== \n";
  67.     cout << "A - Substitute Character \n";
  68.     cout << "B - Count Character \n";
  69.     cin >>select;
  70.     return select;
  71. }
  72. void Second(char Ch, char Su, char Str_2[],int num_1)
  73. {
  74.  
  75.     int i = 0;
  76.     cout << Ch;
  77.     cout << Su;
  78.     cout << "The updated String is: "; 
  79.  
  80.  
  81.  
  82. while(Str_2[i] != '\0')
  83. {
  84.     if(Str_2[i] == Ch)
  85.     {
  86.         Str_2[i] == Su;
  87.     }
  88.     i++;
  89. }
  90. }
Apr 8 '08 #1
3 1281
weaknessforcats
9,208 Recognized Expert Moderator Expert
Have you tried stepping though the code using your debugger?

That will show you the program flow and reveal the contents of all your variables as you go along.

If you don't know how to use your debugger, then this program presents an excellent opportunity.
Apr 8 '08 #2
Learner21
9 New Member
Yea and I got four errors well I had to start all over so here is what I have:
Expand|Select|Wrap|Line Numbers
  1. char Menu();
  2. void insrt_ch(char[], char, char); 
  3. int main()
  4.  
  5. {
  6.  
  7. char Twinkle[80] = {' '};
  8. char select = ' ';
  9. char Sub_char = 'A';
  10. char count = 'B';
  11. char cont = 'Z';
  12. cout <<"Please enter a string: ";
  13. cin.getline(Twinkle, 80); 
  14. cout <<"\n";
  15.  
  16.  
  17.  
  18.     cout << "Welcome to the string program ! \n";
  19.     cout << "=============================== \n";
  20.     cout << "A - Substitute Character \n";
  21.     cout << "B - Count Character \n";
  22.     cin >>select;
  23.     if(select != 'A')
  24.     {
  25.         cout << "Invalid selection! Please re-enter!";
  26.         cin >> select;
  27.     }
  28.  
  29.  
  30.     return select;
  31.  
  32. char String_1[80] = {' '};
  33.         char character = ' ';
  34.         char sub = ' ';
  35.         int i = 0;
  36.         switch(select)
  37.         {
  38.         case 'A':
  39.         case 'a':
  40.             {
  41.                 cout << "Please enter the character to be scanned: ";
  42.                 cin >> character;
  43.                 cout << "Please enter the character to be substituted: ";
  44.                 cin >> sub;
  45.                 insrt_ch(character, sub, String_1);
  46.  
Now what I need to do since I have the second function as well and this is what I have so far I am not going to debug because I want to make sure that I have what I need. Instruction is:
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. Its alot I know and I apologize but really I just want tknow if I am doing it right so far thanks again
Apr 9 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
[quote-Learner21]
insrt_ch(character, sub, String_1);
[/quote]

When you make this call, String_1 does not have the contents of Twinkle.

Also, this code:
etc....
cin >>select;
if(select != 'A')
{
cout << "Invalid selection! Please re-enter!";
cin >> select;
}


return select; <<<<<<<<<<<<<<<<<<<<<<<

char String_1[80] = {' '};
etc....
is going to have a hard time getting past this return. That is going to terminate main().
Apr 9 '08 #4

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

Similar topics

14
2715
by: saayan | last post by:
Hi, I am using PHP 5.0.1 with Apache 2 on Win XP (SP2). My index.php file has require_once contents.php and also for functions.php. My contents.php file also has a require_once for...
2
8802
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
2
2308
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message....
21
3807
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
16
3144
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
28
4272
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
9
3263
by: CryptiqueGuy | last post by:
Consider the variadic function with the following prototype: int foo(int num,...); Here 'num' specifies the number of arguments, and assume that all the arguments that should be passed to this...
3
6719
by: Max Vit | last post by:
I have come across a strange issue whilst trying to use a shell command call from Access and have spent some time trying to figure this out but can't find the cause as yet. The issue is: I need...
53
8315
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
5
2666
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
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,...
1
7023
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...
1
5037
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...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.