code says error, expected ';'

I was working on this code and it worked fine in the university lab but when I rewrote the code at home it keeps giving this error
expected ';' before 'fr'

and after I put a ';' before fr, I got
expected ';' before 'cout'

it worked afterwards but during lectures, they did not inform us to do so. Can someone please explain to me why and what's wrong with my code?
Moreover, .exe file kept closing before calculating the results so my lecturer said to include #include <conio.h> at the beginning and getch () at the end. they didn't mention why. Can someone please explain to me what is that and why we include it? Why does.exe file close before showing the calculated result?
Thank you

[code]

#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

int main()
{
const double pi=3.14159;
double i, e, r, f, l, c, fr;

cout <<"Enter the Frequency(Heartz): "<< endl;
cin >> f;
cout <<"Enter the Resistance(Ohms): "<< endl;
cin >> r;
cout <<"Enter the Capacitance(Farads): "<< endl;
cin >> c;
cout <<"Enter the Inductance(Henrys): "<< endl;
cin >> l;
cout <<"Enter the Electromotive Force(Volts): "<< endl;
cin >> e;

double eq1=2*pi*f*l;
double eq2=1/(2*pi*f*c);

i=e/sqrt(pow(r,2)+pow(eq1-eq2,2))

fr=1/(2*pi*sqrt(l*c))

cout <<"The Current is " << i << "A" << endl;
cout <<"The Reasonant Frequency is " << fr << "Hz" << endl;

getch();

return 0;
}
Your code with code tags, making it easier to point out your errors. Yes, multiple missing ;

One error message that hide two similar errors:
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
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

int main()
{
   const double pi = 3.14159;
   double i, e, r, f, l, c, fr;

   cout << "Enter the Frequency(Heartz): " << endl;
   cin >> f;
   cout << "Enter the Resistance(Ohms): " << endl;
   cin >> r;
   cout << "Enter the Capacitance(Farads): " << endl;
   cin >> c;
   cout << "Enter the Inductance(Henrys): " << endl;
   cin >> l;
   cout << "Enter the Electromotive Force(Volts): " << endl;
   cin >> e;

   double eq1 = 2 * pi * f * l;
   double eq2 = 1 / (2 * pi * f * c);

   i = e / sqrt(pow(r, 2) + pow(eq1 - eq2, 2))  // <----- no ;

   fr = 1 / (2 * pi * sqrt(l * c))  // <----- no ;

   cout << "The Current is " << i << "A" << endl;
   cout << "The Reasonant Frequency is " << fr << "Hz" << endl;

   getch();

   return 0;
}

Lines 25 & 27, both missing the ending ;

Error messages usually get you near where the errors are, it is your duty to look around and see what the exact problem(s) might be.
oh, I didn't know that we needed to add ; after a mathematical equation. It works fine now! Also about #include<conio.h> and getch(), can you please explain the use and function of it?
Thank you so much!
Hello darshaaa,

When it comes to the code tags and the others this should help. http://www.cplusplus.com/articles/z13hAqkS/

Furry Guy wrote:
Error messages usually get you near where the errors are

Most times if the error is not in the line number provided by the error message it is usually in the line above.

I have had one program where the error started 10 lines above the line number of the error message.

The more that you have to work with these error messages the easier it will be to understand.

Andy
Thank you!
Hello darshaaa,

Sorry I did not see this in your code. It became more noticable in Furry Guy's post.

salem c once wrote:

#include<conio.h>
Obsolete since 1990, when the world stopped using DOS as a primary operating system.


Using "conio.h" may work for you at school, but not every one has this header file to use and if they do happen to have it the file is not what it use to be.

C++ does not have a replacement for "getch()", but this code I use is a fair replacement for getch() or system("pause").

1
2
3
4
5
6
7
/ A fair C++ replacement for "system("pause")". Or a way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();

return 0;  // <--- Not required, but makes a good break point. 

Line 3 is the most portable way of writing this line although you could use std::cin.ignore(1000, '\n');. You just need a large number for the first parameter. Also you can change "std::cin" to the name of a file stream when working with a file.

Andy
Topic archived. No new replies allowed.