Thread: New, making a survey program

  1. #16
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> string ans1 = "";
    It's always a good idea to initialize your variables, but in this case doing string ans1; does initialize the string to be empty (since string is actually a class). So even if you are appending to the string that will be fine. Also, don't forget to #include <string> or the code won't compile on some compilers.

    >> int ready = "";
    That looks like it should be string ready; since you are asking for a Yes/No answer.

    >> it just says " press any key to continue " and no errors show up..
    You should probably get compile errors. If you don't and it compiles, you should definitely get to the part where it says "Enter your full name: ". Does that happen?

  2. #17
    Registered User
    Join Date
    Nov 2006
    Location
    Mount Sterling, Ohio
    Posts
    8
    Allright I played around with everything fixed my small errors; and I got it running but the problem im experiencing now well heres the code
    Code:
    // survey.cpp - This is a survey of 20 Christmas questions, The program will ask, user will answer, program will save answers then print.
    // Created/Revised by <Jeff Shaffer> on <11-27-06>.
    
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    
    int main()
    {
    	//Declare string variables
    	string name = "";
    	string ans1 = "";
    	string ans2 = "";
    	string ans3 = "";
    	string ans4 = "";
    	string ans5 = "";
    	string ans6 = "";
    	string ans7 = "";
    	string ans8 = "";
    	string ans9 = "";
    	string ans10 = "";
    	string ans11 = "";
    	string ans12 = "";
    	string ans13 = "";
    	string ans14 = "";
    	string ans15 = "";
    	string ans16 = "";
    	string ans17 = "";
    	string ans18 = "";
    	string ans19 = "";
    	string ans20 = "";
        
    
    	//Enter input data
    	cout << "Enter your full name: ";
    	getline(cin, name);
    	cout << "This survey consists of 20 basic questions"<<endl;
    	
        
    	//Program asks the user the question, user types in answer and program saves the answer
    	cout << "Hot chocolate or apple cider: ";
    	getline(cin, ans1);
    	cout << "Turkey or Ham: ";
    	getline(cin, ans2);
    	cout << "Do you get a fake or 'real cut' Xmas tree: ";
    	getline(cin, ans3);
    	cout << "Decorations on the outside of your house: ";
    	getline(cin, ans4);
    	cout << "Snowball fights or sledding: ";
    	getline(cin, ans5);
    	cout << "Do you like hanging around the fireplace because its warm: ";
    	getline(cin, ans6);
    	cout << "Do you enjoy xmas shopping: ";
    	getline(cin, ans7);
    	cout << "Favorite christmas song: ";
    	getline(cin, ans8);
    	cout << "Take a break, you at 9/20 "<<endl;
    	cout << "how do you feel about christmas movies: ";
    	getline(cin, ans9);
    	cout << "when is it to early to start listening to christmas music: ";
    	getline(cin, ans10);
    	cout << "Stockings before or after presents: ";
    	getline(cin, ans11);
    	cout << "do you like christmas carolers: ";
    	getline(cin, ans12);
    	cout << "go to someone elses house or they come to yours: ";
    	getline(cin, ans13);
    	cout << "do you read the christmas story the night before christmas: ";
    	getline(cin, ans14);
    	cout << "Do you enjoy christmas?: ";
    	getline(cin, ans15);
    	cout << "Did you get someone a gift: ";
    	getline(cin, ans16);
    	cout << ": Do you think you'll get any presents: ";
    	getline(cin, ans17);
    	cout << "what do you eat for christmas dinner: ";
    	getline(cin, ans18);
    	cout << "Do you beleive in Santa Clause: ";
    	getline(cin, ans19);
    	cout << "Thanks for taking our survey, Your all finished" << endl;
    
    	//Displaying the answers for the survey instructor to copy down
    	cout << "Please do not close the program, The instructor will now begin to copy down your answers" >> endl;
    	cout << "Answer #1:" << ans1 << endl;
    	cout << "Answer #2:" << ans2 << endl;
        cout << "Answer #3:" << ans3 << endl;
    	cout << "Answer #4:" << ans4 << endl; 
        cout << "Answer #5:" << ans5 << endl; 
    	cout << "Answer #6:" << ans6 << endl; 
    	cout << "Answer #7:" << ans7 << endl;
        cout << "Answer #8:" << ans1 << endl; 
        cout << "Answer #9:" << ans8 << endl; 
        cout << "Answer #10:" << ans10 << endl; 
        cout << "Answer #11:" << ans11 << endl; 
        cout << "Answer #12:" << ans12 << endl; 
        cout << "Answer #13:" << ans13 << endl; 
        cout << "Answer #14:" << ans14 << endl; 
        cout << "Answer #15:" << ans15 << endl; 
        cout << "Answer #16:" << ans16 << endl; 
        cout << "Answer #17:" << ans17 << endl; 
        cout << "Answer #18:" << ans18 << endl; 
        cout << "Answer #19:" << ans19 << endl; 
        cout << "Answer #20:" << ans20 << endl; 
    
    }   // end of main function
    I get like 45 error when i compile that, Their random errors that talk about stuff that does involve my code at all, IT worked fine until I added
    Code:
    //Displaying the answers for the survey instructor to copy down
    	cout << "Please do not close the program, The instructor will now begin to copy down your answers" >> endl;
    	cout << "Answer #1:" << ans1 << endl;
    	cout << "Answer #2:" << ans2 << endl;
        cout << "Answer #3:" << ans3 << endl;
    	cout << "Answer #4:" << ans4 << endl; 
        cout << "Answer #5:" << ans5 << endl; 
    	cout << "Answer #6:" << ans6 << endl; 
    	cout << "Answer #7:" << ans7 << endl;
        cout << "Answer #8:" << ans1 << endl; 
        cout << "Answer #9:" << ans8 << endl; 
        cout << "Answer #10:" << ans10 << endl; 
        cout << "Answer #11:" << ans11 << endl; 
        cout << "Answer #12:" << ans12 << endl; 
        cout << "Answer #13:" << ans13 << endl; 
        cout << "Answer #14:" << ans14 << endl; 
        cout << "Answer #15:" << ans15 << endl; 
        cout << "Answer #16:" << ans16 << endl; 
        cout << "Answer #17:" << ans17 << endl; 
        cout << "Answer #18:" << ans18 << endl; 
        cout << "Answer #19:" << ans19 << endl; 
        cout << "Answer #20:" << ans20 << endl;
    Someone shine some light on me? ALSO my original plans were to PRINT the answers but i wasnt sure the print syntax.. if anyone could maybe tell me that then I would rather print then just say the answers back. Thank you

  3. #18
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    I don't see anything wrong with, it but it will be easier to read the output if you put \n newlines between each of the answers, like this:

    Also, since you took the time to get the users name, you might as well display it before you output the results. That way your instructor can see who took the quiz.

    cout << "\nAnswer #18: " << ans18 << endl;

    I'm stupid and I don't know exactly how endl is suppoed to be used, so you might check that out.
    Last edited by IdioticCreation; 12-01-2006 at 10:18 AM.

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Post the compile errors, even if you don't understand them, when you code won't compile. If there are a tone of errors, post the first ten or so.
    Code:
    cout << "Please do not close the program, The instructor will now begin to copy down your answers" >> endl;
    Look really hard at that line of code, something in there is backwards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making a program run on startup
    By Poincare in forum C Programming
    Replies: 10
    Last Post: 06-21-2009, 12:50 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Making interest rate program in C
    By canadas321 in forum C Programming
    Replies: 6
    Last Post: 06-23-2005, 11:59 AM
  5. I need help with making a program which....
    By Tonyukuk in forum C# Programming
    Replies: 1
    Last Post: 04-16-2003, 10:49 PM