bit of help with please :)

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 19
Reputation: slawted is an unknown quantity at this point 
Solved Threads: 0
slawted slawted is offline Offline
Newbie Poster

bit of help with please :)

 
0
  #1
Jun 18th, 2009
hello guys i recieve errors when compiling my code
  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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 149
Reputation: monkey_king is on a distinguished road 
Solved Threads: 8
monkey_king monkey_king is offline Offline
Junior Poster

Re: bit of help with please :)

 
0
  #2
Jun 18th, 2009
post your compile errors
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: slawted is an unknown quantity at this point 
Solved Threads: 0
slawted slawted is offline Offline
Newbie Poster

Re: bit of help with please :)

 
0
  #3
Jun 18th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: bit of help with please :)

 
0
  #4
Jun 18th, 2009
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.

  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. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: slawted is an unknown quantity at this point 
Solved Threads: 0
slawted slawted is offline Offline
Newbie Poster

Re: bit of help with please :)

 
0
  #5
Jun 18th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,813
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: bit of help with please :)

 
0
  #6
Jun 18th, 2009
I mean a }. You have a { on line 32, with no matching }. There could be other problems too, but that's definitely ONE problem.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: bit of help with please :)

 
0
  #7
Jun 19th, 2009
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: bit of help with please :)

 
0
  #8
Jun 19th, 2009
Originally Posted by WaltP View Post
See this for formatting help
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?
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 19
Reputation: slawted is an unknown quantity at this point 
Solved Threads: 0
slawted slawted is offline Offline
Newbie Poster

Re: bit of help with please :)

 
0
  #9
Jun 19th, 2009
thank you for your support guys
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,831
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: bit of help with please :)

 
0
  #10
Jun 19th, 2009
Originally Posted by tux4life View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC