Wrong and unexpected

Do you see something wrong with the code that cause compiler failure?

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
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()

{
  while ( true )
   {
   	int a, b, c;
    	double m1, m2, m3, total;
    	cout<<"Enter viewers aged 2>5: "<<endl;
    	cin>>a;
    	cout<<"Enter viewers aged 7>17: "<<endl;
    	cin>>b;
    	cout<<"Enter adult viewers: "<<endl;
    	cin>>c;
    	cout<<endl;
      
      //This function displays number of viewers as users inputed
    	int viewer[]={a, b, c};
    	cout<<"Numbers of viewers for each category: "<<endl;
    	cout<<"-------------------------------------"<<endl;
    	cout<<"Category 1: ";
    	cout<<viewer[0]<<endl;
    	cout<<"Category 2: ";
    	cout<<viewer[1]<<endl;
    	cout<<"Category 3: ";
    	cout<<viewer[2]<<endl<<endl;
    	
        cout<<"Largest viewers among categories:"<<endl;
        if (viewer[0] >= viewer[1] && viewer[0] >= viewer[2]);
           {
	      cout<<"Category 1: "<< viewer[0]  <<endl;
           }
        if (viewer[1] >= viewer[0] && viewer[1] >= viewer[2]);
           {
	      cout<<"Category 2: "<< viewer[1] <<endl;
	   }
    	if (viewer[2] >= viewer[0]viewer[0 && viewer[2] >= viewer[1]);
           {
	      cout<<"Category 3: "<< viewer[2] <<endl;
	   }  
      
      //This is the process to calculate collection value
    	m1 = viewer[0] * 2;
    	m2 = viewer[1] * 3;
    	m3 = viewer[2] * 5;
    	total = m1 + m2 + m3;
      
      //This function is to show total of money collected from each category
    	double money[]={m1, m2, m3};
    	cout<<"Collection Obtained (RM): "<<endl;
    	cout<<"-------------------------------------"<<endl;
    	cout<<"Category 1: ";
    	cout<<money[0]<<endl;
    	cout<<"Category 2: ";
    	cout<<money[1]<<endl;
    	cout<<"Category 3: ";
    	cout<<money[2]<<endl;
    	cout<<"*****Total= "<< total<<endl<<endl;
    	
      
     
      //This function is to show date&time	
        time_t now = time(0);
        char* dt = ctime(&now);
    
      //This function ask users weather to repeat program or not
    	char selection;
    	cout<<"Calculate Again? (y/n)"<<endl;
        cin>>selection;
        if (selection == 'Y' || selection == 'y')
              {
	            return main();
	      }
	if (selection == 'n' || selection == 'N' );
              {
	            cout<<"Program terminated at "<<dt<<endl;
                    break;
	      }
   }
    
}
Last edited on
Lines 73 to 76 should be removed. Just removed.

You have put semicolons at the ends of lines 32, 36, 40 which will terminate those if blocks immediately. Remove those semicolons.

Your compiler tells you which line the error is on. Line 40 is a mess.
Last edited on
Topic archived. No new replies allowed.