# Thread: Alittle help for a beginner please...

1. ## Alittle help for a beginner please...

Ok doing a progy in c++ to average 4 numbers. Seems simple enough. Its for school, and I'm take vb and c++ together. well anyways. I can't seem to understand how to make it loop when I want and terminate when I want. I'm sure it's simple enough, but I've failed to see how to do it. Any help would be appreciated.

Code:
```#using <mscorlib.dll>
#include <stdlib.h>
#include <iostream>

using namespace std;
using namespace System;

int main()

{
double a = 0;
double b = 0;
double c = 0;
double d = 0;
double Average = 0.0;
String *anotherAverage = "";
Boolean Y = 1;
Boolean N = 0;

do

{system("CLS");

Console::Write("Enter first number: ");
a = Convert:: ToDouble(Console::ReadLine());

Console::Write("Enter second number: ");

Console::Write("Enter third number: ");
c = Convert:: ToDouble(Console::ReadLine());

Console::Write("Enter fourth number: ");
d = Convert:: ToDouble(Console::ReadLine());

Average = a + b + c + d /4;

Console::WriteLine("Average: {0}",
Average.ToString("N2"));

Console::Write("Do you want to get another average? (Y/N)");
}
while (anotherAverage != 0);
cin.get();

return 0;
}

//end of main function```

oh, and this is my first ever program written from scratch...so don't be to harsh, with practice and time I hope to become ALOT better. Thanks again.

2. What output does it give you anyways anything?

3. you should put () around a + b + c + d
so that it looks like this

((a + b + c + d)/4)

also can i recommend looking up
cout and cin

4. yeah, I get the desired average of the numbers entered. I just can't figure out how to make it do (Y/N) part. Y for do it again, and N for not. I can get one or the other, but not both working .

cin.get() tells it to pause til key press...right?...cout not so sure one though, i'll look it up.

5. he must know about cout and cin he used cin.get()

6. ok well i posted too quickly i would use a character and use getch(); its alot easier and it waits for a keyboard hit just do a Y/N awnser. BTW that needs conio.h

7. oh yea i ment to say

while (anotherAverage != 0);

should be

while (anotherAverage != 'N');

and anotherAverage doesnt need to be
declared as a string for using on onyl character
a char declartion is sufficent, also for best results maybe
the while should be

while(anotherAverage != 'N' || anotherAverga != 'n')

8. Originally Posted by JarJarBinks
oh yea i ment to say

while (anotherAverage != 0);

should be

while (anotherAverage != N);

same thing N is defined as 0; and that would loop forever seeing as how N NEVER changes

9. Originally Posted by JarJarBinks
oh yea i ment to say

while (anotherAverage != 0);

should be

while (anotherAverage != 'N');

and anotherAverage doesnt need to be
declared as a string for using on onyl character
a char declartion is sufficent, also for best results maybe
the while should be

while(anotherAverage != 'N' || anotherAverga != 'n')

I had it previously that way, and I still had my issue, so i've been messin around with it.

10. why is 'N' defined as 0 ?

11. Just make the character lower case or upper case im sure there is a function if not its easy to write...

12. Boolean N = 0;

13. 0 false or what ever but still !N == true which can also be defined as any number that != 0

14. Maybe this then ?

Code:
```while (anotherAverage != 0);
{
system("CLS");

Console::Write("Enter first number: ");
a = Convert:: ToDouble(Console::ReadLine());

Console::Write("Enter second number: ");

Console::Write("Enter third number: ");
c = Convert:: ToDouble(Console::ReadLine());

Console::Write("Enter fourth number: ");
d = Convert:: ToDouble(Console::ReadLine());

Average = ((a + b + c + d) /4);

Console::WriteLine("Average: {0}",
Average.ToString("N2"));

Console::Write("Do you want to get another average? (Y/N)");