943,544 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 886
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 18th, 2009
0

bit of help with please :)

Expand Post »
hello guys i recieve errors when compiling my code
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. int main() {
  6.  
  7. std::string firstname, lastname, age, emailadress, message;
  8. char answer;
  9.  
  10. std::cout << "Hello please imput your first name: ";
  11. std::getline(std::cin, firstname);
  12. std::cout << "\nNow please enter your last name: ";
  13. std::getline(std::cin, lastname);
  14. std::cout << "\nYour age: ";
  15. std::getline(std::cin, age);
  16. std::cout << "\nContact email: ";
  17. std::getline(std::cin, emailadress);
  18. std::cout << "\nNow finally what is your message: ";
  19. std::getline(std::cin, message);
  20. std::cout << "\nPress Enter to continue.\n\n";
  21. std::cin.ignore(255,'\n');
  22. std::cout << "The following infomation has been recieved...\n";
  23. std::cout << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: ";
  24. std::cout << emailadress << "\nMessage: " << message;
  25. std::cout << "\n\nPress Enter to continue.\n\n";
  26. std::cin.ignore(255,'\n');
  27. std::cout << "Would you like to subit your message: [Y/N] ";
  28. switch (answer) {
  29. case 'Y':
  30. case 'y':
  31. std::ofstream fileOutput("Customer support.txt", std::ios::app);
  32. if (fileOutput.is_open()) {
  33.  
  34. fileOutput << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: " << emailadress << "\nMessage: " << message;
  35.  
  36. fileOutput.close();
  37. std::cout <<"\n\nThank you for your submission, your infomation has been saved. We will contact you shortly.\n";
  38. break;
  39. case 'N':
  40. case 'n':
  41. std:: cout <<"Thank you anyway.";
  42.  
  43. break;
  44. default:
  45. std::cout <<"Please choose an option, would you like to submit your message: [Y/N]";
  46. }
  47. std::cin.ignore(255,'\n');
  48. return 0;
  49.  
  50.  
  51. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slawted is offline Offline
19 posts
since Jun 2009
Jun 18th, 2009
0

Re: bit of help with please :)

post your compile errors
Reputation Points: 70
Solved Threads: 9
Junior Poster
monkey_king is offline Offline
160 posts
since Aug 2008
Jun 18th, 2009
0

Re: bit of help with please :)

sure

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\Users\Michael\Desktop\C++\FIRST REAL.cpp" -o "C:\Users\Michael\Desktop\C++\FIRST REAL.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp: In function `int main()':
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:39: error: jump to case label
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:31: error: crosses initialization of `std::ofstream fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:40: error: jump to case label
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:31: error: crosses initialization of `std::ofstream fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:44: error: jump to case label
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:31: error: crosses initialization of `std::ofstream fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:39: warning: destructor needed for `fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:39: warning: where case label appears here
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:39: warning: (enclose actions of previous case statements requiring destructors in their own scope.)
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:40: warning: destructor needed for `fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:40: warning: where case label appears here
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:44: warning: destructor needed for `fileOutput'
C:\Users\Michael\Desktop\C++\FIRST REAL.cpp:44: warning: where case label appears here

Execution terminated
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slawted is offline Offline
19 posts
since Jun 2009
Jun 18th, 2009
0

Re: bit of help with please :)

You have a brackets problem. You need to indent your code so that blocks of code line up. Otherwise you can't see brackets problems. You have an if statement (line 32) with a starting bracket but no ending bracket. Indent the code properly and the lack of bracket will really stick out. You can't see it when the code is indented as you have indented it.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. int main() {
  6.  
  7. std::string firstname, lastname, age, emailadress, message;
  8. char answer;
  9.  
  10. std::cout << "Hello please imput your first name: ";
  11. std::getline(std::cin, firstname);
  12. std::cout << "\nNow please enter your last name: ";
  13. std::getline(std::cin, lastname);
  14. std::cout << "\nYour age: ";
  15. std::getline(std::cin, age);
  16. std::cout << "\nContact email: ";
  17. std::getline(std::cin, emailadress);
  18. std::cout << "\nNow finally what is your message: ";
  19. std::getline(std::cin, message);
  20. std::cout << "\nPress Enter to continue.\n\n";
  21. std::cin.ignore(255,'\n');
  22. std::cout << "The following infomation has been recieved...\n";
  23. std::cout << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: ";
  24. std::cout << emailadress << "\nMessage: " << message;
  25. std::cout << "\n\nPress Enter to continue.\n\n";
  26. std::cin.ignore(255,'\n');
  27. std::cout << "Would you like to subit your message: [Y/N] ";
  28. switch (answer) {
  29. case 'Y':
  30. case 'y':
  31. std::ofstream fileOutput("Customer support.txt", std::ios::app);
  32. if (fileOutput.is_open()) {
  33.  
  34. fileOutput << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: " << emailadress << "\nMessage: " << message;
  35.  
  36. fileOutput.close();
  37. std::cout <<"\n\nThank you for your submission, your infomation has been saved. We will contact you shortly.\n";
  38. break;
  39. case 'N':
  40. case 'n':
  41. std:: cout <<"Thank you anyway.";
  42.  
  43. break;
  44. default:
  45. std::cout <<"Please choose an option, would you like to submit your message: [Y/N]";
  46. }
  47. std::cin.ignore(255,'\n');
  48. return 0;
  49.  
  50.  
  51. }
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,371 posts
since Jan 2008
Jun 18th, 2009
0

Re: bit of help with please :)

do you mean a { or a ( ? cause i still says the case 'N' is wrong
Last edited by slawted; Jun 18th, 2009 at 8:02 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slawted is offline Offline
19 posts
since Jun 2009
Jun 18th, 2009
0

Re: bit of help with please :)

I mean a }. You have a { on line 32, with no matching }. There could be other problems too, but that's definitely ONE problem.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,371 posts
since Jan 2008
Jun 19th, 2009
0

Re: bit of help with please :)

Moderator
Reputation Points: 3275
Solved Threads: 890
Posting Sage
WaltP is offline Offline
7,716 posts
since May 2006
Jun 19th, 2009
0

Re: bit of help with please :)

Or use AStyle for code formatting

To the OP (please don't take this personal): What do you want? A bit of help or a byte of help?
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 19th, 2009
0

Re: bit of help with please :)

thank you for your support guys
Reputation Points: 10
Solved Threads: 0
Newbie Poster
slawted is offline Offline
19 posts
since Jun 2009
Jun 19th, 2009
0

Re: bit of help with please :)

Click to Expand / Collapse  Quote originally posted by tux4life ...
Or use AStyle for code formatting
Or use Visual Studio and press CTRL-A, CTRL-K, CTRL-F.
Or if linux is your taste: Use Netbeans and click source->format.

I'm sure most IDE's have this kind of functionality build in
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006

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:





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


Follow us on Twitter


© 2011 DaniWeb® LLC