a problem!

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
143
144
145
#include <iostream.h>
int main()
{
float a, b, c, d, e, f, g, h, z, y, i, q, w;
char o;
cout<<"what you wanna do???\n";
cin>>q;
if (q==1)

{
         for(w=1;(w<=10);w=++w)
        { 
                    system("CLS");             
cout<<"first side\n";
cin>>a;
cout<<"second side\n";
cin>>b;
cout<<"third side\n";
cin>>c;
if ((a>b)&&(a>c))
{
d=b+c;
if (d>a)
cout<<"triangle is valid\n";
else
cout<<"it is not valid\n";
system("pause");
}
else if((b>c)&&(b>a))
{
d=c+a;
if(d>b)
cout<<"triangle is valid\n";
else
cout<<"triangle not valid\n";
system("pause");
}
else if((c>a)&&(c>b))
{
d=a+b;
if(d>c)
cout<<"triangle is valid\n";
else
cout<<"triangle not valid\n";
system("pause");
}
}
}
else if (q==2)
{
         w=1;
         while(w<=10)
         {
                     system("CLS");
cout<<"tell 1 side\n";
cin>>a;
cout<<"2nd\n";
cin>>b;
cout<<"and 3rd\n";
cin>>c;
if((a==b)&&(b==c)&&(c==a))
cout<<"equilatera; triangle\n";
else if((a==b&&a!=c)||(b==c&&b!=a)||(a==c&&c!=b))
cout<<"iscosceles\n";
else if((a!=b)||(a!=c)||(b!=c))
cout<<"scalene\n";
w=++w;
system("pause");
}
}
else if(q==3)
{
         w=1;
         while(w<=12)
         {
                    system("CLS");
                    cout<<"enter the total number of marks\n";
                    cin>>h;
                    cout<<"the total number of subjects??\n";
                    cin>>i;
                    cout<<"subject 1:\n";
                    cin>>a;
                    cout<<"sunbject 2\n";
                    cin>>b;
                    cout<<"subject3\n";
                    cin>>c;
                    cout<<"subject4\n";
                    cin>>e;
                    cout<<"subject5\n";
                    cin>>f;
                    g=a+b+c+d+e+f;
                    z=h*i;
                    y=(g/z)*100;
                    cout<<"percentage is  "<<y<<"%";
                    w=++w;
                    system("pause");
                    }                    
                    else if(q==4)
                    
                    {
                            system("pause");
                             for(w=1;(w<=190);w=++w)
                             {
                                                    system("pause");
                             system("CLS");
                             cout<<"ohk you want the calculator\nno problem we habe got it TOO!!haha\nthen lets get started\n";
                             cout<<"what do you want to do?\n";
                             cin>>o;
                             if(o=='A')
                             { 
                                        cout<<"enter first number";
                                        cin>>a;
                                        cout<<"ENTER SECOND NUMBER";
                                        cin>>b;
                                        cout<<"enter third number";
                                        cin>>c;
                                        d=a+b+c;
                                        cout<<"there you go, so the sum is:"<<d;
                                        system("pause");                                        
                                        }
                              if(o='M')
                             {
                              cout<<"enter the first number";
                              cin>>a;
                              cout<<"enter the second number";
                              cin>>b;
                              c=a*b;
                              cout<<"the product is"<<c<<"\n";
                              system("pause");
                                  }
                                  else if(o='D')
                                  {
                                  cout<<"enter the first number";
                              cin>>a;
                              cout<<"enter the second number";
                              cin>>b;
                              c=a/b;
                              cout<<"the quotient is"<<c<<"\n";
                              system("pause");
                              }
                             }
                             }
         }
return 0;
}


sorry guyzz if the code is creepy.. the code was working fine till if(q==3) but after if(q==4) it has lots of error .. please tell me, where i am wrong.

thanking you
Last edited on
I highly recommend that you break up this code into separate, self-contained functions. That will make it much easier for both yourself and everyone else to follow what the code is doing.

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
#include <iostream>
using namespace std;

void section1();
void section2();

//---------------------------------------
int main()
{
    int q;
    cout<<"what you wanna do???\n";
    cin>>q;

    switch (q)
    {
        case 1:
            section1();
            break;
        case 2:
            section2();
            break;
        // Add extra choices here ...

        default:
            cout << "\nInvalid choice\n";
    }

    cin.ignore(1000, '\n');
    cin.get();

    return 0;
}

//---------------------------------------
void section1()
{
    // Add the code for section one here
}

void section2()
{
    // Add the code for section two here
}
Last edited on
tha problem is that i still havent gained any type of knowledge about void.. i have not reached that chapter.
its been only 6 days till i started leaning c++.

anyway thank you for your concern, i guess i have to make the if(q==4) part again.. 2 delete all my mistakes.
Last edited on
My problem, in trying to help, is that I find your code so very complex that it's difficult to follow. (and if it's difficult for me, it must be mind-boggling for a beginner).

My alternative recommendation is that you start a brand-new program and delete all of the code, except that which concerns part 4.

Use <iostream>, not <iostream.h>
You had out of place brackets..
Organization, spacing, layout are important for readable code.
Your intro to your program: "What you wanna do????" ... How does the user know what to enter? an integer? a string? what are the choices?

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
143
144
145
146
147
148
149
150
151
#include <iostream.h> //deprecated
#include <iostream>
using namespace std;

int main()
{
float a, b, c, d, e, f, g, h, z, y, i, q, w;
char o;
cout<<"what you wanna do???\n";
cin>>q;
if (q==1)

{
         for(w=1;(w<=10);w=++w)
        {
                    system("CLS");
cout<<"first side\n";
cin>>a;
cout<<"second side\n";
cin>>b;
cout<<"third side\n";
cin>>c;
if ((a>b)&&(a>c))
{
d=b+c;
if (d>a)
cout<<"triangle is valid\n";
else
cout<<"it is not valid\n";
system("pause");
}
else if((b>c)&&(b>a))
{
d=c+a;
if(d>b)
cout<<"triangle is valid\n";
else
cout<<"triangle not valid\n";
system("pause");
}
else if((c>a)&&(c>b))
{
d=a+b;
if(d>c)
cout<<"triangle is valid\n";
else
cout<<"triangle not valid\n";
system("pause");
}
}
}
else if (q==2)
{
         w=1;
         while(w<=10)
         {
                     system("CLS");
cout<<"tell 1 side\n";
cin>>a;
cout<<"2nd\n";
cin>>b;
cout<<"and 3rd\n";
cin>>c;
if((a==b)&&(b==c)&&(c==a))
cout<<"equilatera; triangle\n";
else if((a==b&&a!=c)||(b==c&&b!=a)||(a==c&&c!=b))
cout<<"iscosceles\n";
else if((a!=b)||(a!=c)||(b!=c))
cout<<"scalene\n";
w=++w;
system("pause");
}
}
else if(q==3)
{
         w=1;
         while(w<=12)
         {
                    system("CLS");
                    cout<<"enter the total number of marks\n";
                    cin>>h;
                    cout<<"the total number of subjects??\n";
                    cin>>i;
                    cout<<"subject 1:\n";
                    cin>>a;
                    cout<<"sunbject 2\n";
                    cin>>b;
                    cout<<"subject3\n";
                    cin>>c;
                    cout<<"subject4\n";
                    cin>>e;
                    cout<<"subject5\n";
                    cin>>f;
                    g=a+b+c+d+e+f;
                    z=h*i;
                    y=(g/z)*100;
                    cout<<"percentage is  "<<y<<"%";
                    w=++w;
                    system("pause");
                    }
}

}                                                                          // ADDED!
                    else if(q==4)

                    {
                            system("pause");
                             for(w=1;(w<=190);w=++w)
                             {
                                                    system("pause");
                             system("CLS");
                             cout<<"ohk you want the calculator\nno problem we habe got it TOO!!haha\nthen lets get started\n";
                             cout<<"what do you want to do?\n";
                             cin>>o;
                             if(o=='A')
                             {
                                        cout<<"enter first number";
                                        cin>>a;
                                        cout<<"ENTER SECOND NUMBER";
                                        cin>>b;
                                        cout<<"enter third number";
                                        cin>>c;
                                        d=a+b+c;
                                        cout<<"there you go, so the sum is:"<<d;
                                        system("pause");
                                        }
                              if(o='M')
                             {
                              cout<<"enter the first number";
                              cin>>a;
                              cout<<"enter the second number";
                              cin>>b;
                              c=a*b;
                              cout<<"the product is"<<c<<"\n";
                              system("pause");
                                  }
                                  else if(o='D')
                                  {
                                  cout<<"enter the first number";
                              cin>>a;
                              cout<<"enter the second number";
                              cin>>b;
                              c=a/b;
                              cout<<"the quotient is"<<c<<"\n";
                              system("pause");
                              }
                             }
                             }                                                     //REMOVED!

return 0;
}
but it is still not working
i am using dev c++
the error is in the
104 
line
Last edited on
Did you add the other brace as I did?

1
2
3
4
5
6
system("pause");
                    }
}

}        // ADDED!
                    else if(q==4)
Last edited on
yup i copied and pasted the whole thing.
it says'

  expected unqualified id before eise
expected `,' or `;' before "else" 
Ok, my apologies. Remove that bracket. I had added two brackets instead of one.

1
2
3
4
5
6
system("pause");
                    }
}

}        // ADDED!
                    else if(q==4)
Last edited on
thank you so much , finally got it working!
You are using floats for some variables that should be integral type:

if (q==1)

This bit won't work for floats, because direct float comparisons don't work:
for(w=1;(w<=10);w=++w)

w=++w is better written as w++

The usual idiom for looping 10 times is:
1
2
3
4
5
int a;
for(a = 0;(a < 10);a++) {
//do some stuff

}


Instead of having a load of if else clause's use a switch instead, call functions from each case.

Also learn how to use arrays or vectors rather than 12 variables - what if you had to find the average of 1000 numbers?

Any time you find yourself writing the same code over & over, then it needs to be a function. You have this lots of times:

1
2
3
4
cout<<"enter the first number";
                              cin>>a;
                              cout<<"enter the second number";
                              cin>>b;


Good Luck !!!!!
Topic archived. No new replies allowed.