...

A few C++ related questions

Nightfire
12-07-2002, 11:22 PM
I've been using C++ for about 1 - 2 hours, and I've got a small program built but I'd like it checking over to see if I'm coding right - before I start getting used to bad syntax or whatever

#include <iostream>
#include <string>
using namespace std;

int main()
{
int age, feet, inches, pounds;
string hair, eye, correct;

cout << "Please type your answer to each question"
<< " followed by <enter>:" << endl;
cout << "What is your age (years)? ";
cin >> age;
cout << "\nHow tall are you (ft in)? ";
cin >> feet >> inches;
cout << "\nHow much do you weigh (lbs)? ";
cin >> pounds;
cout << "\nWhat colour is your hair? ";
cin >> hair;
cout << "\nWhat colour are your eyes? ";
cin >> eye;

cout << endl << "\nYou are "<< age <<" years old, "
<< feet << " feet " << inches << " inches tall."
<< "\nYou weigh "<< pounds <<" pounds,"
<< " have "<< hair <<" coloured hair and "
<< eye << " coloured eyes." << endl;

cout << "\nIs this correct? ";
cin >> correct;
if (correct == "yes"){
cout << "\nThank you" << endl;
}else{
cout << "\nWell it's what you put in..." << endl;
}
return 0;
}

Also, I noticed something called vector on one site. What is this?

Also, at the end of the program, the window closes before I get a chance to see what the end result says (although I know myself what it is, others won't).

Another thing, how can I make the answer yes case insensitive, so ppl can answer YeS and still get the Thank you message?

Josh Campbell
12-08-2002, 05:06 AM
Use:

char dummy;
printf("Press <enter> to quit.")
scanf("%c",&dummy);

The screen will wait to close until the input buffer is flushed (by pressing enter). I am a C'er and havent done much c++ so i am not sure how that would be with the cins and couts.

jkd
12-08-2002, 04:32 PM
char dummy;
cin >> dummy;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum