Intro to Functions assignment

Hey there, my assignment was to create a program that asks for 3 values, calculates/outputs the average of the values, then outputs the standard deviation, all within a do while loop that stops once the user enters capital or lowercase 'n'. Basically wanted some explanation as to why entering 'n' or 'N' isn't causing the script to stop while testing. Besides that, does the algorithm for finding standard deviation seem correct? so far haven't tested it too much but seems to be working for the values i've already tried.. thanks in advance

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
29
30
31
32
33
34
35
36
#include <iostream>
#include <cmath>
using namespace std;
  
void deviation(double, double, double, double);
  
int main()
   {
       double num1, num2, num3, avg;
 
      char choice;
 
      do{
      cout << "Enter 3 doubles: ";
      cin >> num1 >> num2 >> num3;
      avg = (num1+num2+num3)/3;
      cout << "\nThe average is: " << avg;
      deviation(num1, num2, num3, avg);
      cout << "\nDo you wish to enter another set of data? (y|n)";
      cin >> choice;
      }while(choice != 'n' || choice != 'N');
 
      cout << "Goodbye!";
 
      return 0;
  }
 
void deviation(double num1, double num2, double num3, double avg){
      double sdev;
 
      sdev = sqrt( (pow((num1-avg),2) + pow((num2-avg),2) + pow((num3-avg),2)
    ) / 3           );
 
      cout << "\nThe standard deviation is: " << sdev;
  }
 



}while(choice != 'n' || choice != 'N'); should be }while(choice != 'n' && choice != 'N');
Topic archived. No new replies allowed.