Why does it assign wrong value???

Hey guys,my exams are near, so I wondered why not make a program to guess my Marks (and the aggregate percentage).So I began writing a small program (really, no voodoo-stuff in it) for myself and this is the source code :-
(Sorry for this,but my browser seems not to support the code assimilation process).

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

#include<iostream>
#include<random>




using namespace std;

class Result
{
private :
    default_random_engine dre;
    int high,low;
public :
    Result()
    {
    high=Timer(1,1000);
    low=Timer(1,1000);
    }
    ~Result()
    { delete this; }

    int getOpinion()
    {
    string s;
    int opine;
    cout<<"Enter your opinion of your exam,ie, how did/will it go???    Excellent(E) , Very Good(VG) , Good(G) , Okay(O) , Bad(B) , Very Bad(VB)  "<<endl;
    cin>>s;
/*    if((s!="Excellent") || (s!= "Very Good") || (s!="Good") || (s!="Okay") || (s!="Bad") || (s!="Very Bad"))
  *    {
  *    cout<<"Bad choice!!! Exiting.\n";
  *    return 0;
      } */
    if(s=="E") {opine= 0; return opine;} // 95 to 90
    else if(s=="VG") {opine =1; return opine;} // 90 to 85
    else if(s=="G") { opine = 2 ; return opine; } // 85 to 70
    else if(s=="O") {opine=3; return opine;} //70 to 55
    else if(s=="B") {opine=4; return opine;} // 55 to 40
    else if(s=="VB") {opine=5; return opine;} //40 to 20
    else { cout<<"Bad choice!!! Exiting.\n"; return 0;}
    }

    inline int Timer(int a,int b)
    {
    std::uniform_int_distribution<int> di(a,b);
    int c;
    for(int i=1;i<1000;i++)
    {
    c=di(dre);
    }
    return c;
    }

    int compResult()
    {
    int result = 0;
    int o;
    o = getOpinion();
    if(o==0)
     {
       result= Timer(90,95);
       return result;
     }
     else if(o==1)
     {
      result= Timer(85,90);
      return result;
     }
     else if( 0 == 2 )
     {
      result = Timer(70,85);
      return result;
     }
     else if(o==3)
     {
     result= Timer(55,70);
     return result;
     }
     else if(o==4)
     {
     result= Timer(40,55);
     return result;
     }
     else if(o==5)
     {
     result = Timer(20,40);
     return result;
     }
     return result;
    }

    int getExamResult()
    {
      int a;
      a = compResult();
      return a;
    }
};


And here is my main program :-

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

int main()
{
Result *r = new Result;
int P=0,C=0,E=0,H=0,Comp=0;
int M=0;

H = r->Timer(1,1000);


cout<<"This is for Maths exam...\n";
M = r->getExamResult();

cout<<"Next,this is for Physics exam...\n";
P = r->getExamResult();

cout<<"Next,this is for Chemistry exam...\n";
C = r->getExamResult();

cout<<"Next,this is for English exam...\n";
E = r->getExamResult();

cout<<"Next,this is for Computer exam...\n";
Comp= r->getExamResult();

cout<<"Your results are :- \n"
    <<"Maths : "<<M<<endl
    <<"Physics : "<<P<<endl
    <<"Chemistry : "<<C<<endl
    <<"English : "<<E<<endl
    <<"Computer : "<<Comp<<endl;

int avg;
avg = ( M + P + C + E + Comp)/5;

cout<<"And your percentage is : "<<avg<<" % "<<endl;

cout<<"Thank you!!!\n";
delete r;
return 0;
}


Again,if after my posting this code(aka; mess) feels a pain in the eye I'm sorry.Its for reasons some light-years away from this forum.

But when you run this code,for whatever reasons,when the user types 'G' (for 'Good') in the terminal for how did their exam go,then it just gives/assigns the variable 0. Can you guys explain where I'm wrong???
Sorry again.
On line 70 you are using integer literal 0 instead of variable o.

Oh!! Sorry Peter for not seeing tht,I should have been careful.
Anyways thnx for your time :) .
One more thing, I dont know what you're trying to do here, but you definitely should not -

1
2
3
4
~Result()
{ 
    delete this; // What exactly do you think you are deleting here? There is nothing to delete, especially not by suicide.
}
Last edited on
Topic archived. No new replies allowed.