Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

C++ program help....


  • Please log in to reply

#1
pomp

pomp

    the man

  • Member
  • PipPipPipPip
  • 1,366 posts
Hey, I'm coding a program for an assignment, it's pretty much done.

It has to do with fstream. It's a survey-like program.

The first and third question need the same answers (Yes or No). It's confusing on how to keep track of the yes's and no's for each individual question since it's one variable that needs to have the same input. Included is the code, and attached is the ifstream text file.


#include <iostream>
#include <fstream>
#include <string>


using namespace std;






int main()
{

string String_Convert_To_Lower( string answer );
int yes = 0;
char Keep_Goin;
int pc = 0;
int mac = 0;
int other = 0;
int neither = 0;
int no = 0;
string line;
string answer;
	


  do{
	ifstream in("surveyquestions.txt");
    ofstream out("completedsurvey.txt");




	while(!in.eof())
	{
	

  
  getline(in,line,'\n');
  cout << line << '\n';
  out << line;
        cin >> answer;
  answer = String_Convert_To_Lower(answer);
  
        
  out << answer << '\n';




  if(answer == "yes")
  {
 	 yes++;
 	 out << "\tYes: " << yes << '\n';
  }
  else if(answer == "no")
  {
 	 no++;
 	 out << "\tNo: " << no << '\n';
  }
  if(answer == "pc" || answer == "mac"  || answer == "other" || answer == "neither")
  {
         
 	 if(answer == "pc")
 	 {
    pc++;
 	 
 	 } 
 	 else if(answer == "mac")
 	 {
    mac++;
  
 	 }
 	 else if(answer == "other")
 	 {
    other++;
 	 
 	 }
 	 else if(answer == "neither")
 	 {
    neither++;
  
 	 }
              out << "\tPC: " << pc << '\n';
        out << "\tMAC: " << mac << '\n';
        out << "\tOTHER: " << other << '\n';
        out << "\tNEITHER: " << neither << '\n';
  
	}

	}

in.close();
out.close();

	int go = 3;

	if(go == 3)
	{
  cout << "Do you want to go (y/n): ";
  cin >> Keep_Goin;
	}
}while(Keep_Goin == 'y');

	
return 0;
}



string String_Convert_To_Lower(string answer)
{
	for( int i = 0; i < answer.length(); i++)
	{
   answer.at(i) = tolower(answer.at(i) );

}
	return answer;

}
[attachment=745:attachment][attachment=745:attachment][attachment=746:attachment]

Edited by pomp86, 07 May 2005 - 01:31 PM.

  • 0

Advertisements


#2
cauli1

cauli1

    Member

  • Member
  • PipPip
  • 25 posts
Hi. Looks good to me. Nice job.
:tazz:
  • 0

#3
pomp

pomp

    the man

  • Topic Starter
  • Member
  • PipPipPipPip
  • 1,366 posts
Thanks.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP