943,945 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1434
  • C++ RSS
May 26th, 2005
0

Need Help Quickly

Expand Post »
My Program :

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. void Reverse(string &InputString);
  6.  
  7.  
  8. void CharSwap(char& First, char& Second);
  9.  
  10. void main(void)
  11. {
  12. string InputString;
  13.  
  14. cout << "Please enter the string to reverse ==> ";
  15. getline(cin, InputString);
  16.  
  17. cout << endl << "You entered the (" << InputString.length()
  18. << ") char long string: ";
  19. for(int i = 0; i < InputString.length(); i++)
  20. cout << InputString[i];
  21.  
  22.  
  23. Reverse(InputString);
  24.  
  25.  
  26. cout << endl << "The string reversed is : ";
  27. for(int j = InputString.length(); j > 0 ; j--)
  28. cout << InputString[j];
  29.  
  30.  
  31. cout << endl << endl;
  32.  
  33. }
  34.  
  35.  
  36. void Reverse(string &InputString)
  37. {
  38. int Begin = 1,
  39. End = InputString.length();
  40.  
  41. while(Begin < End)
  42. {
  43. CharSwap(InputString[Begin], InputString[End]);
  44. Begin++;
  45. End--;
  46. }
  47. }
  48.  
  49.  
  50. void CharSwap(char& First, char& Second)
  51. {
  52. char Temp;
  53. First = Second;
  54. Temp = First;
  55. Second = Temp;
  56. }
<< moderator edit: added [code][/code] tags >>




Will not work It comes up with the error message "Line 11 `main' must"

How do i fix this thanks
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hazzo is offline Offline
2 posts
since May 2005
May 26th, 2005
0

Re: Need Help Quickly

Quote originally posted by hazzo ...
Will not work It comes up with the error message "Line 11 `main' must"
...have return type int?
Quote originally posted by hazzo ...
How do i fix this
Uh, give main a return type of int.
C++ Syntax (Toggle Plain Text)
  1. int main()
  2. {
  3. // ...
  4. return 0;
  5. }
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 27th, 2005
0

Re: Need Help Quickly

What what should the code look like with int main()
{
// ...
return 0;
}

where do i place it ?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hazzo is offline Offline
2 posts
since May 2005
May 27th, 2005
0

Re: Need Help Quickly

Where you have
void main(void)
Change it to
int main(void)
Then return a value before the last }.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
May 27th, 2005
0

Re: Need Help Quickly

You might have to rethink your CharSwap() function or you end up with two Seconds, a runtime error.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: why use c?
Next Thread in C++ Forum Timeline: How to recieve input from user such as "#help"





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC