A stupid mistake I can't see?

Now, I've had quite a lot of trouble with stupid errors in my time. My time, which is very limited. I'm a fairly new programmer, and I have a situation here. I'm all good up to where I enter 'P' or 'R'. Entering an invalid character will loop back and ask for another input just fine. However, when entering a valid character, the program ends. I have no idea why it it completely missing the switch structure/the rest of int main(). I added a test at the end to see if it would just skip the switch or the entire int main, and I found out it skips the entire main function after sending back (or attempting to send back sevtype.)

I've even stumped my instructor on this one. Help is more than appreciated.

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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream> 
#include <iomanip>
#include <string>
#include <time.h>
#include <stdlib.h>


using namespace std; 

string account;

char sevtype = 'a';

double amount;

int regmin;
int daymin;
int nightmin;

const double regserv = 10.00; 
const double rpermin = 0.20;
const double preserv = 25.00;
const double pperday = 0.10;
const double ppernight = 0.05;

void welcome();
void reg();
void pre();
void choice(char &sevtype);
void cou();

int main()

{ 
	
	welcome();
	
	choice(sevtype);
	
	
		switch (sevtype)
	 {
	 case 'r':
	 case 'R':
		 void reg();

     break;
	 
	 case 'p':
	 case 'P': 
		 void pre(); 

	  break;
	  
	  void cou();

	 }
}

void welcome() {
	cout << "Please enter your account password: ";  
	cin >> account;
	cout << '\n';
}

void choice(char &sevtype)
{
	while (sevtype != 'r' && sevtype != 'R' && sevtype != 'p' && sevtype != 'P')
	{
	cout << "Enter a service code: R or r (Regular), P or p (Premium): ";
    cin >> sevtype;
	cout << '\n';
	if (sevtype != 'r' && sevtype != 'R' && sevtype != 'p' && sevtype != 'P') 
	{
		cout << "Invalid.\n";
	}
}
	
	}
	
	void reg(double &amount)
	{	 
		 cout << "Enter the number of minutes used: ";
		 cin >> regmin; 
		 cout << '\n'; 
		if (regmin < 0 || regmin > 40320)
		{
			cout << "The number you have entered in invalid. You may not excede 40320 minutes or be below 1 minute.";
		}
	  if (regmin > 50)
	     {
		   amount = regserv + ((regmin - 50) * rpermin);
	     }
      else
        amount = regserv;

	}

	void pre(double &amount)
	{
		 cout << "Enter the minutes used for the day: ";
		 cin >> daymin; 
		 cout << '\n';
		 
		 if (daymin > 720 || daymin < 0)
		 {
		 	cout << "Invalid.";
		 }
		     

      if (daymin > 75) 
		  {
		  amount = preserv + ((daymin - 75) * pperday);
		}
	  else
         {
          amount = preserv;
		}
	     
		 cout << "Enter the minutes used for the night: ";
     	 cin >> nightmin; 
		 cout << '\n';
      	
      	if (nightmin > 720 || nightmin < 0)
      {
      	cout << "Invalid";
      }
      
      if (nightmin > 100)
		  {
		  amount = preserv + ((nightmin - 100) * ppernight);
		}
	  else 
		 {
		  amount = preserv; 
		}
	}
	
	void cou()
	{
		cout << "Test.";
	}
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
int main()
{ 

  welcome();
  
  choice(sevtype);
  
  
  switch (sevtype)
  {
   case 'r':
   case 'R':
   //void reg(); Don't do this, this is like delaring a header
      reg(//Needs an amount in here);

      break;

      case 'p':
      case 'P': 
     //void pre(); Don't do this either
     pre(//Needs an amount in here); 

     break;

     default://without this, the function below will not execute
     //If you need to call that function regardless of options above
     //then you might want to call the function before the breaks in 
     //the above cases
     //ex reg(double& somenum);
     //   cou();
     //   break;



    //void cou();
     cou();

   }
 }


This means you have to redo your function headers as:
1
2
void reg(double&);
void pre(double&);
Last edited on
I need a slap on the head for that one. Thanks so much, mate.
Topic archived. No new replies allowed.