I am not sure how to do this..

Hi my question is when I run the program it is asking what the score was for a student and after each score it asks 'more?'and you have to type 'y' or 'n' to continue. Well whatever I press it doesn't stop whether its 'n' or 'm'. My other question is how do I make the program quit if I press anything else other than a number when its asking for a score?

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>


int main()
{
	using namespace std;
	
	char ans, more;
	void FirstName();
	void LastName();
	const int SIZE = 10;  
   float scores[SIZE]; 
   float total = 0;   

void FirstName();
{
    string fName;
    do
    {
        cout << "First name: ";

        getline(cin, fName);
     

    }
    while(fName == "");

}

void LastName();
{
    string lName;
    do
    {
        cout << "Last name: ";


        getline(cin, lName);
        
    }
    while(lName == "");

   
}

int i;
  
 
  for (int i = 0; i < SIZE; i++)
   {
      cout << "Score " << i + 1 << ": ";
      cin >> scores[i];
	  cout<<"More? :";
	  cin>>more;
   }

  if (more == 'y' || more == 'Y')
  {
	  cin>>scores[i];
  }
  if (more == 'n' || more == 'N')
  {
	cout<<"end";
  }
    else
  {
	cout<<"end";
  }

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

  if (more == 'y' || more == 'Y' || more == 'n' || more == 'N')
  {
	  cout<<"end"<<endl;
  }
  else
  {
	cout<<"end";
  }
	return 0;
}
double post?

btw why do you have functions inside your main?
First thing first,move your fuctions outta the main() function.You might wanna prompt the user to press "this" to exit,then follow it by a simple "return" statement e.g.
1
2
3
4
case 1:
return;
break;
//honestly i dont know how you want it to be,not necessarily a switch structure,a single if check might do you well. 
Last edited on
So I put my functions out of main but is it ok if I don't put anything inside my main?
Topic archived. No new replies allowed.