Okay, so I'm a bit confused... here are my instructions for making a program:

1. Input each test result (i.e. a 1 or a 2). Display the message " Enter result" on the screen each time the program requests another test result.

2. Count the number of test results of each type.

I have no idea how to do number 2 the only thing I know how to do is like... record a variable. (using the cin>>) I don't know how I would actually count how many times something was entered.

Any help? I think the book I'm using is crazy and asking me to make programs of stuff I haven't learned yet.. (Awesome book).

Okay, so I'm a bit confused... here are my instructions for making a program:

1. Input each test result (i.e. a 1 or a 2). Display the message " Enter result" on the screen each time the program requests another test result.

2. Count the number of test results of each type.

I have no idea how to do number 2 the only thing I know how to do is like... record a variable. (using the cin>>) I don't know how I would actually count how many times something was entered.

Any help? I think the book I'm using is crazy and asking me to make programs of stuff I haven't learned yet.. (Awesome book).

Why not have some kind of increment to a globally scoped variable (or a variable declared above your input/cout display) ?

For example...

int a = 0;
char word[256] = {0}; //nully terminated char array
cout << "Enter something" << endl;
cin >> word;
a++;

//later on...

cout << "number of times you've entered something is: "<< a << endl;

Not quite sure what a++ is or char.... soo... yeah... But I think I figured out what they were talking about...

for example:

int apples = 1, passes = 0, fails = 0, result;

while (apples <= 10)
{
cout>>"Enter result" : ";
cin<< result;

if (result == 1)
passes = passes +1;
else 
failures = failures +1;

Kinda forgot about learning the whole if/else.

Not quite sure what a++ is or char.... soo... yeah... But I think I figured out what they were talking about...

for example:

int apples = 1, passes = 0, fails = 0, result;

while (apples <= 10)
{
cout>>"Enter result" : ";
cin<< result;

if (result == 1)
passes = passes +1;
else 
failures = failures +1;

Kinda forgot about learning the whole if/else.

cout goes with the << operator, not the >> operator. cin goes with the >> operator, not the << operator. You have them backwards.

a++

is the same as:

a = a + 1;

Looks like you have a decent start on it, though it's incomplete. You are correctly initializing your counters to 0 outside of the loop. You are then going through a loop, and within that loop asking for data. Also within that loop, you have an if-else statement where you add one to one of the counters. Now you need to finish the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.