CODE HELP!!!

ok, after almost finishing my first usable program. I started to debug and i got a couple of errors which i cant fix. This is my code and the errors are at the bottom. Thanx ;)
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

#include<iostream.h>
using namespace std;
int main() {
     char loop = 'y';
     char operand;
     float f1;
     float f2;
     float f3;
     system("TITLE Calculator V2.01");
     system("COLOR 2");
     
     do while(loop == 'y' || loop == 'Y')
     {     
           system("CLS");
           cout <<" Welcome to Calculator Program V2" << endl;
           cout << " Please type in your first integer or decimal: "; 
           cin >> f1;
           cout << " Now select a operation you wish to complete(-,+,*, or /): ";
           cin >> operand;
           cout << " Finally, type in your last integer or decimal: ";
           cin >> f2;
           cout << endl << endl;
           
           switch(operand)
           {              
                          case '+' :
                               f3 == f1 + f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "+" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '-' :
                               f3 == f1 - f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "-" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '*' :
                               f3 == f1 * f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "*" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '/' :
                               if( f2 == 0){
                                   cout << "That is a invalid operation" << endl;
                                   }
                               else{
                                    f3 == f1 / f2;
                                    cout << "The answer is " << f3 << endl;
                                    cout << f1 << "/" << f2 << "=" << f3 << endl;
                                    }
                          break;
                          
                          default :
                               cout << "That is a invalid operation" << endl;
                          break;
           }
           cout << "Would you like to start again? [y/n]: ";
           cin >> loop;
           system("PAUSE");
           return 0; 
           }


32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 32:2

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected `while' at end of input

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected `(' at end of input

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected primary-expression at end of input

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected `)' at end of input

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected `;' at end of input

62 C:\Documents and Settings\user\My Documents\calculator.cpp expected `}' at end of input

THNAKX AGAIN xd
closed account (z05DSL3A)
Try changing
#include<iostream.h>
to
 
#include<iostream> 


and

1
2
3
4
5
6
7
     do while(loop == 'y' || loop == 'Y')
     {
...
     }
     cout << "Would you like to start again? [y/n]: ";
     cin >> loop;
...

to
1
2
3
4
5
6
7
     do 
     {
...
           cout << "Would you like to start again? [y/n]: ";
           cin >> loop;
     } while(loop == 'y' || loop == 'Y')
     
Last edited on
i changed iostream

do ...code... while and do while just differently placed. I think its something else

i did it anyways same think cept the header error is gone
closed account (z05DSL3A)
You have a closing brace '}' missing.

Also you are using '==' insdead of '=' in your case statments
f3 == f1 + f2; should be
f3 = f1 + f2;

there may be other errors.
Last edited on
closed account (z05DSL3A)
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
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() 
{
     char loop = 'y';
     char operand;
     float f1;
     float f2;
     float f3;
     system("TITLE Calculator V2.01");
     system("COLOR 2");
     
     do 
     {     
           system("CLS");
           cout <<" Welcome to Calculator Program V2" << endl;
           cout << " Please type in your first integer or decimal: "; 
           cin >> f1;
           cout << " Now select a operation you wish to complete(-,+,*, or /): ";
           cin >> operand;
           cout << " Finally, type in your last integer or decimal: ";
           cin >> f2;
           cout << endl << endl;
           
           switch(operand)
           {              
                          case '+' :
                               f3 = f1 + f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "+" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '-' :
                               f3 = f1 - f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "-" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '*' :
                               f3 = f1 * f2;
                               cout << "The answer is " << f3 << endl;
                               cout << f1 << "*" << f2 << "=" << f3 << endl;
                          break;
                          
                          case '/' :
                               if( f2 == 0){
                                   cout << "That is a invalid operation" << endl;
                                   }
                               else{
                                    f3 = f1 / f2;
                                    cout << "The answer is " << f3 << endl;
                                    cout << f1 << "/" << f2 << "=" << f3 << endl;
                                    }
                          break;
                          
                          default :
                               cout << "That is a invalid operation" << endl;
                          break;
           }
           cout << "Would you like to start again? [y/n]: ";
           cin >> loop;
            
     } while(loop == 'y' || loop == 'Y');
     system("PAUSE");
     return 0;
}
ok thanks it waorks now. that alst post fixed it but what does
#include<stdlib.h>

from apperent noob lol(i am though 2nd day programming)
closed account (z05DSL3A)
#include <stdlib.h> (should really have been #include <cstdlib>) in there to allow the system() function.
Topic archived. No new replies allowed.