| | |
bit of help with please :)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2009
Posts: 19
Reputation:
Solved Threads: 0
hello guys i recieve errors when compiling my code
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include <string> int main() { std::string firstname, lastname, age, emailadress, message; char answer; std::cout << "Hello please imput your first name: "; std::getline(std::cin, firstname); std::cout << "\nNow please enter your last name: "; std::getline(std::cin, lastname); std::cout << "\nYour age: "; std::getline(std::cin, age); std::cout << "\nContact email: "; std::getline(std::cin, emailadress); std::cout << "\nNow finally what is your message: "; std::getline(std::cin, message); std::cout << "\nPress Enter to continue.\n\n"; std::cin.ignore(255,'\n'); std::cout << "The following infomation has been recieved...\n"; std::cout << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: "; std::cout << emailadress << "\nMessage: " << message; std::cout << "\n\nPress Enter to continue.\n\n"; std::cin.ignore(255,'\n'); std::cout << "Would you like to subit your message: [Y/N] "; switch (answer) { case 'Y': case 'y': std::ofstream fileOutput("Customer support.txt", std::ios::app); if (fileOutput.is_open()) { fileOutput << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: " << emailadress << "\nMessage: " << message; fileOutput.close(); std::cout <<"\n\nThank you for your submission, your infomation has been saved. We will contact you shortly.\n"; break; case 'N': case 'n': std:: cout <<"Thank you anyway."; break; default: std::cout <<"Please choose an option, would you like to submit your message: [Y/N]"; } std::cin.ignore(255,'\n'); return 0; }
•
•
Join Date: Jun 2009
Posts: 19
Reputation:
Solved Threads: 0
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

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
•
•
Join Date: Jan 2008
Posts: 3,813
Reputation:
Solved Threads: 501
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)
#include <iostream> #include <fstream> #include <string> int main() { std::string firstname, lastname, age, emailadress, message; char answer; std::cout << "Hello please imput your first name: "; std::getline(std::cin, firstname); std::cout << "\nNow please enter your last name: "; std::getline(std::cin, lastname); std::cout << "\nYour age: "; std::getline(std::cin, age); std::cout << "\nContact email: "; std::getline(std::cin, emailadress); std::cout << "\nNow finally what is your message: "; std::getline(std::cin, message); std::cout << "\nPress Enter to continue.\n\n"; std::cin.ignore(255,'\n'); std::cout << "The following infomation has been recieved...\n"; std::cout << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: "; std::cout << emailadress << "\nMessage: " << message; std::cout << "\n\nPress Enter to continue.\n\n"; std::cin.ignore(255,'\n'); std::cout << "Would you like to subit your message: [Y/N] "; switch (answer) { case 'Y': case 'y': std::ofstream fileOutput("Customer support.txt", std::ios::app); if (fileOutput.is_open()) { fileOutput << "Name: " << firstname << " " << lastname << "\nAge: " << age << "\nEmail Adress: " << emailadress << "\nMessage: " << message; fileOutput.close(); std::cout <<"\n\nThank you for your submission, your infomation has been saved. We will contact you shortly.\n"; break; case 'N': case 'n': std:: cout <<"Thank you anyway."; break; default: std::cout <<"Please choose an option, would you like to submit your message: [Y/N]"; } std::cin.ignore(255,'\n'); return 0; }
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
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?

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."
![]() |
Similar Threads
- Identify a 16-bit Program (Windows tips 'n' tweaks)
- Bit Torrent Forum/Site, help? (Website Reviews)
- what is the difference between regular and 64 bit edition (Windows NT / 2000 / XP)
- slow download speeds on bit torrent (IT Professionals' Lounge)
- I would kill for this, just a little bit (C)
- 128 bit encryption (Viruses, Spyware and other Nasties)
- Learn How to Spot a 16-Bit Application (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: Trouble writing code for arithmetic calculations of complex numbers
- Next Thread: this function not work ! (with string variables )
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






