Void returning functions

How do I make the coding under the void function into function call in the int main?
Format:
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
#include<iostream>
#include<cstring>
#include<iomanip>

using namespace std;
void codeOfIndividual(codeOfIndividual)
{
	
					for (int PT3Sub =0; PT3Sub <4; PT3Sub++)
					{
				    while (PT3Sub<0 || PT3Sub>4)
				    {
				    cout<<"ERROR!!";
				    cout<<"\nHow many subject do you want to register (MAXIMUM - 4 SUBJECTS)? : "; //over limit please choose until 4 subject
				    cin>>PT3Sub; //cin>>countI;
					}
					count=1;
					
				    while(count<= PT3Sub)
			      	{	
			      	
			      	cout<<"\n\nPlease enter code of Individual Subject : ";
						cin>>codeOfIndividualSub;
										
						while(strcmp(codeOfIndividualSub,"BMY")!=0 &&  strcmp(codeOfIndividualSub,"ENG")!=0 && strcmp(codeOfIndividualSub,"SEJ")!=0 && strcmp(codeOfIndividualSub,"MAT")!=0 && strcmp(codeOfIndividualSub,"SCI")!=0 && strcmp(codeOfIndividualSub,"GEO")!=0)
						{
								cout<<"ERROR!!";
								cout<<"\n\nPlease enter code of Individual Subject : ";
								cin>>codeOfIndividualSub;	
						}
						
						if (strcmp(codeOfIndividualSub,"BMY")==0)
						{
							cout<<"\n\nBahasa Melayu";
							tprice17 = 35.00;
							price17=0;
							price17 = tprice17;
							cout<<setprecision(2)<<fixed;
							cout<<"\nPrice for Bahasa Melayu : RM" <<price17; //inside
					
						}
						else if (strcmp(codeOfIndividualSub,"ENG")==0)
						{
							cout<<"\n\nEnglish";
							tprice18 = 35.00;
							price18=0;
							price18 = tprice18;
							cout<<setprecision(2)<<fixed;
							cout<<"\nPrice for English : RM" <<price18; //inside
												
						}
						else if (strcmp(codeOfIndividualSub,"SEJ")==0)
						{
							cout<<"\n\nSejarah";
							tprice19 = 35.00;
							price19=0;
							price19 = tprice19;
							cout<<setprecision(2)<<fixed;
							cout<<"\nPrice for Sejarah : RM" <<price19; //inside				
						
						}

						else
						{
							price = 0.00;
							tax= 0.06;
							price = price + (price*tax);
							cout<<"\nERROR!!"; 
					    }
						TpricePT3Add=0;
						TpricePT3Add = price17 + price18 + price19 + price20 + price21 + price22;
						
					    cout<<setprecision(2)<<fixed;
					    count++; 
						//cout<<"\nTotal price for taken subject(s) : RM" <<TpricePT3; //outside price
						cout<<"\n\nYour total price for Add On subject : RM"<<TpricePT3Add;
					
					} 	
			    
				tax=0.06;
				TpricePT3 = TpricePT3Add + TpricePT3;
				TpricePT3tax = (TpricePT3*tax)+TpricePT3;
				
			           
	           break;
	            
				}
}
int main()
{
				int PT3sub;
				cout<<"\nHow many subject do you want to register (MAXIMUM - 4 SUBJECTS)? : ";
			    cin>>PT3Sub;
			    
			    	cout<<"\n|-------------------------------------------------------------------------------------|";
					cout<<"\n| Category  | Code of Individual |     Subject     |    Time    | Code of | Price per |";
					cout<<"\n|           |      Subject       |                 |            |  Time   |  subject  |";
					cout<<"\n|-------------------------------------------------------------------------------------|";
					cout<<"\n|           |        BMY         |  Bahasa Melayu  |            |         |     35    |";
					cout<<"\n|           |--------------------|-----------------|            |         |-----------|";
					cout<<"\n|           |        ENG         |    English      |            |         |     35    |";
					cout<<"\n|           |--------------------|-----------------|            |         |-----------|";
					cout<<"\n|           |        SEJ         |    Sejarah      |  Weekdays  |    D    |     35    |";
					cout<<"\n|           |--------------------|-----------------|            |         |-----------|";
					cout<<"\n|   PT3     |        MAT         |   Mathematics   |  Weekend   |    E    |     30    |";
				
					
					cout<<"\nHow many subject do you want to register? : ";
				    cin>>PT3Sub;

return 0;
}
Last edited on
C'mon dude, use the [code][/code] tags!


People ignore badly formatted code.
Please up your game.
@salem c , I'm sorry but what does tags mean?
1. Press the edit button under your post.
2. Locate the "Format:" icons to the right of your post.
3. Highlight select all your code.
4. Press the <> icon. Your code should now have [code][/code] tags at each end. You can type these manually if you want.
5. Press "Submit", and you're done.

See also http://www.cplusplus.com/forum/lounge/253680/

@salem C , thank you for your help for the code/code tags. Can you help me with the void question? Thank you so much ^_^
How do I make the coding under the void function into function call in the int main?


For a tutorial on how to call functions, see:

http://www.cplusplus.com/doc/tutorial/functions/

Note that the code you've posted won't even compile. Line 6 is not a valid function signature - you haven't defined the type of the paramater.
@MikeyBoy I'm not sure if I should use string or char for the parameters for line 6
c++ uses string type for multiple characters, such as "hello world". C++ uses char for a single letter, such as 'X'

C uses char* or char array for string, but you should not do this unless you have a good reason (for example a tool I use has this interface, so I have to accept and return char* even if inside I use string). These do work in c++, but it is not a good choice.
Last edited on
Topic archived. No new replies allowed.