473,569 Members | 2,457 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 1284
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(charac ter, 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
2725
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 functions.php. When this code is tested on one machine, it works fine. However on another machine with identical configuration (same PHP 5.0.1, XP+SP2,...
2
8810
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 { public: Book()
2
2315
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. -------------------------------------REPY---------------------------------- Hi Maybe i wasn't clear. I want to dynamically check whether what the lowest date and the highest date is in the calendar table....
21
3822
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 writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one...
16
3145
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 parameter will not be changed - so don't worry. 2. It tells the implementor and the maintainer of this function that the parameter should not be changed...
28
4294
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 function are of type int. (My question has nothing to do with the definition of the function foo, so don't bother about it.) If I call the function...
3
6725
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 to execute a command call from within Access to execute a batch file (sample.bat). To do this, we use the Shell function, something like: Shell...
53
8347
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 language="javascript" type="text/javascript">
5
2672
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 that structure, is this valid? As shown in the code below I am allocating the structure in the function and then returning the structure. I know...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8132
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3656
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
944
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.