GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Nov-2006, 09:38
shaffer shaffer is offline
New Member
 
Join Date: Nov 2006
Posts: 3
shaffer is on a distinguished road

Help with survey program


Yea im trying to make a christmas survey program for my class project, Im using strings to set 20 variables, Not a experienced programmer this is my first year in classes just trying to learn and need a bit of help. my program wont even do anything it says no errors, runs then says press any key to continue.. Any help someone can offer would be greatly appreciated
CPP / C++ / C Code:
// survey.cpp - This is a survey of 30 basic 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>

using std::cout;
using std::cin;
using std::endl;

int main()
{
	//declare 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 ans15 = "";
	string ans15 = "";
	string ans16 = "";
	string ans17 = "";
	string ans18 = "";
	string ans19 = "";
	string ans20 = "";
    int ready = "";

	//Enter input data
	cout << "Enter your full name: ";
	getline(cin, name);
	cout << "This survey consists of 20 basic questions";
	cout << "Ready to begin? Yes/No";
	cin >> ready;
    
	//darw
	cout << "Hot chocolate or apple cider: ";
	cin >> ans1;
	cout << "Turkey or Ham: ";
	cin >> ans2;
	cout << "Do you get a fake or 'real cut' Xmas tree: ";
	cin >> ans3;
	cout << "Decorations on the outside of your house: ";
	cin >> ans4;
	cout << "Snowball fights or sledding: ";
	cin >> ans5;
	cout << "Do you like hanging around the fireplace because its warm: ";
	cin >> ans6;
	cout << "Do you enjoy xmas shopping: ";
	cin >> ans7;
	cout << "Favorite christmas song: ";
	cin >> ans8;
	cout << "Take a break, you at 9/20 ";
	cout << "how do you feel about christmas movies: ";
	cin >> ans10;
	cout << "when is it to early to start listening to christmas music: ";
	cin >> ans11;
	cout << "Stockings before or after presents: ";
	cin >> ans12;
	cout << "do you like christmas carolers: ";
	cin >> ans13;
	cout << "go to someone elses house or they come to yours: ";
	cin >> ans14;
	cout << "do you read the christmas story the night before christmas: ";
	cin >> ans15;
	cout << "Question16: ";
	cin >> ans16;
	cout << "Question17: ";
	cin >> ans17;
	cout << "Question18: ";
	cin >> ans18;
	cout << "Question19: ";
	cin >> ans19;
	cout << "Question20: ";
	cin >> ans20;
	cout << "Thanks for taking our survey, Your all finished";


	  return 0;
	} // end of main function
Last edited by JdS : 30-Nov-2006 at 21:03. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 30-Nov-2006, 10:10
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: help with survey program


Quote:
Originally Posted by shaffer
it says no errors.
.
.
Any help someone can offer would be greatly appreciated

1. The following is illegal. I can't believe any C++ compiler accepted it:
CPP / C++ / C Code:
    int ready = "";
Why not make it a string like everything else?


How about this:
CPP / C++ / C Code:
    string ans13 = "";
    string ans15 = "";
    string ans15 = "";

Two ans15 declarations? I don't believe any compiler would accept that. Be sure and post the code that you actually used. And if there were compiler messages, post them also.

2. When you use cin>> with a string, it only reads one word, so if you enter
"hot chocolate" in response to that question, it only reads "hot" into ans1, and puts "chocolate" into ans2 (without waiting for your response to the next question). Why not use getline() for everything?

3. I think it's a good idea, especially for new programmers, to make the program print out what it is working on whenever it gets user input. That way you know whether it is working or not:

CPP / C++ / C Code:
    cout << "Enter your full name: ";
    getline(cin, name);
    cout << "You entered " << name << endl;
    cout << "This survey consists of 20 basic questions";
    cout << "Ready to begin? Yes/No: ";
    getline(cin, ready);
    cout << "You entered " << ready << endl;

    cout << "Hot chocolate or apple cider: ";
    getline(cin, ans1);
    cout << "You entered " << ans1 << endl;


You can always remove (or comment out) the extra cout statements later.

Regards,

Dave
  #3  
Old 01-Dec-2006, 08:32
shaffer shaffer is offline
New Member
 
Join Date: Nov 2006
Posts: 3
shaffer is on a distinguished road

Re: help with survey program


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
  #4  
Old 01-Dec-2006, 09:05
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: help with survey program


Quote:
Originally Posted by shaffer
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
.
.
.


random errors that talk about stuff that does involve my code at all, IT worked fine until I added
.
.
.
//Displaying the answers for the survey instructor to copy down
CPP / C++ / C Code:
	cout << "Please do not close the program, The instructor will now begin to copy down your answers" >> endl;

This line certainly has an error, and one thing that I personally guarantee is that the error messages are not random. They may be inscrutable but they are not random.

My point is that you should post the exact error messages. If there were 45 messages, don't post all of them, just the first few. I promise you that the error messages will "involve" your code. There may be other errors, but I respectfully suggest you post the exact messages that point out this line. Once you see how to get to the bottom of things, then that becomes part of your life experience in the wonderful world of debugging, and you will have a good chance of recognizing the relevance if you ever see this kind of message again.

Regards,

Dave
  #5  
Old 01-Dec-2006, 09:22
shaffer shaffer is offline
New Member
 
Join Date: Nov 2006
Posts: 3
shaffer is on a distinguished road

Re: help with survey program


Code:
1> c:\program files\microsoft visual studio 8\vc\include\string(425) : see declaration of 'std::operator >>' 1>c:\documents and settings\shaffeje\my documents\visual studio 2005\projects\christmassurvey\christmassurvey\christmassurvey.cpp(96) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::basic_ostream<_Elem,_Traits>'
Theirs one of the errors the rest look almost exactly like them
  #6  
Old 01-Dec-2006, 09:51
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,303
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: help with survey program


Quote:
Originally Posted by shaffer
Code:
1> c:\program files\microsoft visual studio 8\vc\include\string(425) : see declaration of 'std::operator >>' 1>c:\documents and settings\shaffeje\my documents\visual studio 2005\projects\christmassurvey\christmassurvey\christmassurvey.cpp(96) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::operator >>(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::basic_ostream<_Elem,_Traits>'
Theirs one of the errors the rest look almost exactly like them

That's why I wanted to see the exact error. You have to learn to look carefully. I can't see why there would be lots and lots of errors, so I'll just concentrate on the first ones (the ones that you posted):

It is telling you that there is a problem with your use of the operator '>>'.
Specifically, on line 96 of your code.

Here: I will filter the fly specks out of the pepper:

Code:
1> blah-blah-blah- see declaration of 'std::operator >>' 1> blah-blah-blah-christmassurvey.cpp(96) blah-blah-blah


So, look at line 96 of your code and see if there is anything wrong that might involve '>>'

CPP / C++ / C Code:
	cout << "Please do not close the program, The instructor will now begin to copy down your answers" >> endl;

I know that it is very unnerving to see pages and pages of error messages that are seemingly irrelevant, but learning to zero in on the problem is a very important part of programming. No one was born knowing this stuff: it's a learning process.

Now fix that line. Fix it. Don't worry about all of the other errors, just fix it.

Then try to compile again.

Regards,

Dave

Footnote: Another little debugging hint: If it used to work and you changed it, then look carefully at the changes. Comment out some of the stuff that you changed; see if that affects the error messages. (One thing that might result is that you might consider a development strategy that only changes a few things at a time and compiling incrementally. Maybe even executing and testing before making massive changes.)
Last edited by davekw7x : 01-Dec-2006 at 11:01.
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 13:20
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 04:48
How to read particular memory location ? realnapster C Programming Language 10 10-May-2006 10:11
Type casts ? kai85 C++ Forum 12 23-Jun-2005 13:04
fltk-2.0 cvs Plumb FLTK Forum 20 13-Nov-2004 08:10

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:23.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.