By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,118 Members | 1,133 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,118 IT Pros & Developers. It's quick & easy.

Error expected unqualified -id before '{' token

P: 2
I have an assignment that is giving me this annoying error I am wondering if anyone might know what is wrong I am by no means an expert and will take all feedback.
Feb 6 '17 #1
Share this Question
Share on Google+
2 Replies


P: 2
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cctype>
  4. #include <string.h>
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8.  
  9. {
  10.     strcpy(destination,source);
  11. }
  12.  
  13. {
  14.     strcpy(destination,source);
  15.  
  16.     int i=0 ,j=0;
  17.     for (i=strlen(source)-1;i>=0;i--)
  18.     {
  19.         destination[j]=source[i];
  20.         j++;
  21.     }
  22.     return destination;
  23. }
  24.  
  25. {strcpy(destination,source);
  26. int i=0, j=0;
  27. for(i=0;i<strlen(destination);i++)
  28. {
  29.     int ascval = destination[i]
  30.     if(ascval >=97 and ascval<=122) destination[i]-32;
  31. }
  32. return destination;
  33. }
  34.  
  35.  
  36. {
  37.     strcpy(destination,source);
  38.     int i=0;
  39.     for(i=0;i<strlen(destination) ;i++)
  40.     {
  41.         if (destination[i]==target) destination[i] = replace;
  42.  
  43.     }
  44.     return destination;
  45. }
  46. int main()
  47.    {
  48.    const int WORDSIZE = 15;
  49.    char words[][WORDSIZE] = {"cattywampus", "collywobbles", "Lickety Split", "Kerfuffle", "Lollygag", ""};
  50.    char word[WORDSIZE];
  51.  
  52.    // Test the copy function
  53.    cout << "Copy \"cattywampus\", should see \"cattywampus\".\n";
  54.    copy(word, words[0], sizeof(word) - 1);
  55.    cout << word << endl << endl;
  56.  
  57.    // Test the limit on the copy function
  58.    cout << "Copy \"Supercalifragilisticexpialidocious\", should see \"Super\".\n";
  59.    copy(word, "Supercalifragilisticexpialidocious", 5);
  60.    cout << word << endl << endl;
  61.  
  62.    // Test the replaceCopy function
  63.    cout << "Replace 'l' in \"collywobbles\" with 'b', should see \"cobbywobbbes\".\n";
  64.    replaceCopy(word, words[1], 'l', 'b', sizeof(word) - 1);
  65.    cout << word << endl << endl;
  66.  
  67.    // Test the limit on the replaceCopy function
  68.    cout << "Replace 's' in \"Supercalifragilistic\" with 'd', should see \"duper\".\n";
  69.    replaceCopy(word, "Supercalifragilistic", 'S', 'd', 5);
  70.    cout << word << endl << endl;
  71.  
  72.    // Test the caseChangeCopy function
  73.    cout << "Case change \"Lickety Split\", should see \"lICKETY sPLIT\".\n";
  74.    caseChangeCopy(word, words[2], sizeof(word) - 1);
  75.    cout << word << endl << endl;
  76.  
  77.    // Test the limit on the caseChangeCopy function
  78.    cout << "Case change \"Supercalifragilistic\", should see \"sUPER\".\n";
  79.    caseChangeCopy(word, "Supercalifragilistic", 5);
  80.    cout << word << endl << endl;  
  81.  
  82.    // Test the reverseCopy function
  83.    cout << "Reverse \"Kerfuffle\", should see \"elffufreK\".\n";
  84.    reverseCopy(word, words[3], sizeof(word) - 1);
  85.    cout << word << endl << endl;
  86.  
  87.    // Test the limit on the reverseCopy function
  88.    cout << "Reverse \"triskaidekaphobia\", should see \"ohpakediaksirt\".\n";
  89.    reverseCopy(word, "triskaidekaphobia", sizeof(word) - 1);;
  90.    cout << word << endl << endl;
  91.  
  92.    cout << "Reverse \"Lollygag\", change case, and replace 'G' with 'Z', should see \"ZAZYLLOl\".\n";
  93.    replaceCopy(caseChangeCopy(reverseCopy(word, words[4], sizeof(word) - 1), word, sizeof(word) - 1), word, 'G', 'Z', sizeof(word) - 1);
  94.    cout << word << endl << endl;  
  95.  
  96.    cout << "Enter your entire name: ";
  97.    read(words[5], sizeof(words[5]));
  98.    cout << words[5] << endl << endl;  
  99.  
  100.    cout << "Reverse your name and change case.\n";
  101.    cout << caseChangeCopy(reverseCopy(word, words[5], sizeof(word) - 1), word, sizeof(word) - 1) << endl;
  102.  
  103.    return 0;
  104.    }
Feb 6 '17 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
Above main() you have code that's no in a function. All code must be inside a function. You may define variables outside a function but all code instructions must be inside a function.
Feb 7 '17 #3

Post your reply

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