Programming Project Help

< sorry >
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>

int main()
{
    // prompts for the name of a pet
    std::cout << "name of pet? " ;

    std::string name ;
    // should be able to take in more than a single word name
    // http://www.cplusplus.com/reference/string/string/getline/
    std::getline( std::cin, name ) ;

    // prompt the user for whether or not it is male or female
    // accept a single letter answer (M or F). Save it into a character.
    std::cout << "male or female (M/F)? " ;
    char m_or_f ; // *** note: char 
    std::cin >> m_or_f ;
    
    // if we got either an 'M' or an 'F', proceed with the program 
    if( m_or_f == 'M' || m_or_f == 'F' ) //  // *** note: there are quotes around character literals
    {
        // prompt the user for the animals weight and age.
        // Store these in two integers.

        // TO Do: rest of program
    }
}

Take it up from there.
Thanks for the help. I think you would benefit if you used "using namespace std;" on top of the code next to #include <string>. Then you wouldn't have to type "std"

Thanks,
Sparrow

@StrikingSparrow

Actually, instead of using namespace std;
you could write
1
2
3
4
5
using std::cout;
using std::cin;
using std::string;
using std::endl;
// and any other namespace command you're using 

Then you don't have to put std:: in front of the commands in the source code you're writing.
Then you don't have to put std:: in front of the commands in the source code you're writing.


But it's best practise to do exactly that :+)

I used to do the "using" thing a long time ago, but that gets tiresome - it's easy to accumulate lots of those when using various STL containers and algorithms.

@StrikingSparrow

First up don't delete your original post. It's not helpful.

Second, pay careful attention to what JLBorges does - he is an expert :+)
Thanks for the help and advice everyone. Will delete original post in the future.
Topic archived. No new replies allowed.