I dont know how to do this.. Anyone please

I am trying to make it read:
First Name:
Last Name:
Score 1: " "
More? Y
Score 2: " "
More? N

That is the output but when it asks 'more?' whatever I press it keeps going to the next score. How do I make it quit the program when I type the letter n or N?

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <string>
#include <iomanip>



int main()
{
	using namespace std;
	
	string fName, lName;
	char ans, more;
	const int SIZE = 10;  
    float scores[SIZE]; 
    float total = 0;  
	int i;

	cout << "First Name: ";
	getline(cin,fName);

	if (fName.length() != 0)
	{
		cout << "Last Name: ";
		getline(cin,lName);
	}
	else
	{
		cout << "Invalid input!!";
		
	}
	
 
  for ( i = 0; i < SIZE; i++)
   {
      cout << "Score " << i + 1 << ": ";
      cin >> scores[i];
	  cout<<"More? :";
	  cin>>more;
	 
   }


  if (more != 'y' || more != 'Y')
  {
	  cin>>scores[i];
  }

  else
  {
	  cout<<"The end"<<endl;
  }

  for ( i = 0; i < SIZE; i++)
   {
      total += scores[i];
   }

  if (more == 'y' && more == 'Y' && more == 'n' && more == 'N')
  {
	  cout<<"end"<<endl;
  }

	return 0;
}
You don't understand the meaning of 'or' and you don't understand the meaning of 'and'.

more != 'y' || more != 'Y'
This is always, ALWAYS true.

more == 'y' && more == 'Y' && more == 'n' && more == 'N'
This is always, ALWAYS false.
Last edited on
You would have something along these lines:
1
2
3
4
if(more == 'n' || more == 'N')
{
    return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
for ( i = 0; i < SIZE; i++)
{
      cout << "Score " << i + 1 << ": ";
      cin >> scores[i];
      cout<<"More? :";
      cin>>more;

      if( more != 'y' && more != 'Y' )
      {
         //nothing to do here
         break;
      }
}


edit: forgot to put anything but code. This looks a good candidate for breaking out of the loop if the user says they want no more. As Moschops said you gotta think about what your if conditions could evaluate out to.
Last edited on
tyty
Topic archived. No new replies allowed.