Hello all :p

I was working on this simple program with a formula for
calculating parallel resistance. I was getting all kinds
of errors at first but I am still getting these few.

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(5) : warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
G:\VC++60\ResistancePar\ResistancePar.cpp(5) : error C2146: syntax error : missing ';' before identifier 'RPar'
G:\VC++60\ResistancePar\ResistancePar.cpp(5) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

ResistancePar.obj - 2 error(s), 1 warning(s)

#include <iostream>
using namespace std;
int main (void)

float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;

{
char quantity;	
	
cout << "Enter the quantity of resistors" << endl;
cout << "A maximum of 6 resistors please" << endl;
cin >> quantity;
switch (quantity)

{
case '1':
cout << " You must enter at least 2";
break;
case '2':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> "Rtwo;
	Rpar = (Rone * Rtwo) / (Rone + Rtwo);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '3':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> "Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> "Rthree;
	Rpar = (Rone * Rtwo * Rthree) / (Rone + Rtwo + Rthree);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '4':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> "Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> "Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> "Rfour;
	Rpar = (Rone * Rtwo * Rthree * Rfour) / (Rone + Rtwo + Rthree + Rfour);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '5':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> "Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> "Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> "Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> "Rfive;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive) / (Rone + Rtwo + Rthree + Rfour + Rfive);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '6':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> "Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> "Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> "Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> "Rfive;
	cout << " Enter the value of the sixth resistor";
	cin >> "Rsix;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive * Rsix) / (Rone + Rtwo + Rthree + Rfour + Rfive + Rsix);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";


}
return 0;
}

Any help would be appreciated.

Thanks, BandM

try changing the

int main (void) ...

to int main () {

should read like this

int main () {

float ......

and no { here.

Also,
You should probably make quantity an 'int', and then in your switch, it would be: (Note no ' ' around the number)

case 1:
cout << " You must enter at least 2";
break;
case 2:
cout << " Enter the value of the first resistor";
..etc..

Also, you should put a default case case...

default:
cout<<"In valid number:"<<quantity<<endl;

I tried that and I still got some errors

I changed it ti this:

#include <iostream>
#include <cmath>
using namespace std;
int main()


;float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
char quantity;
{

	
	
cout << "Enter the quantity of resistors" << endl;
cout << "A maximum of 6 resistors please" << endl;
cin >> quantity;
switch (quantity)


case '1':
cout << " You must enter at least 2";
break;
case '2':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	Rpar = (Rone * Rtwo) / (Rone + Rtwo);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '3':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	Rpar = (Rone * Rtwo * Rthree) / (Rone + Rtwo + Rthree);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '4':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	Rpar = (Rone * Rtwo * Rthree * Rfour) / (Rone + Rtwo + Rthree + Rfour);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '5':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive) / (Rone + Rtwo + Rthree + Rfour + Rfive);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case '6':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	cout << " Enter the value of the sixth resistor";
	cin >> Rsix;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive * Rsix) / (Rone + Rtwo + Rthree + Rfour + Rfive + Rsix);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";



return 0;
}

Now I am just getting this:

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(9) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

ResistancePar.obj - 1 error(s), 0 warning(s)

Thanks BandM

Move this:
float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;

to be above int main()

Move this:
char quantity;

to be after:
int main()
{
char quantity;

Also after switch( quantity), you need a { and after all of the case logic you need another }

Well, I have gotten down to one error.
missing function header.
Anyone have any ideas?

#include <iostream>
#include <cmath>
using namespace std;
int main()

;float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
int quantity;

{

	
	
cout << "Enter the quantity of resistors" << endl;
cout << "A maximum of 6 resistors please" << endl;
cin >> quantity;
switch (quantity)


case 1:
cout << " You must enter at least 2";
break;
case '2':
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	Rpar = (Rone * Rtwo) / (Rone + Rtwo);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 3:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	Rpar = (Rone * Rtwo * Rthree) / (Rone + Rtwo + Rthree);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 4:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	Rpar = (Rone * Rtwo * Rthree * Rfour) / (Rone + Rtwo + Rthree + Rfour);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 5:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive) / (Rone + Rtwo + Rthree + Rfour + Rfive);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 6:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	cout << " Enter the value of the sixth resistor";
	cin >> Rsix;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive * Rsix) / (Rone + Rtwo + Rthree + Rfour + Rfive + Rsix);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";



return 0;
}

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(9) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

ResistancePar.obj - 1 error(s), 0 warning(s)


BandM :o

This:

int main()

;float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
int quantity;

{

should be like this:

int main()
{
   float Rpar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
   int quantity;

Then some more errors that can be fixed by enclosing the statements for the switch within {}. And this:

case '2':

should be this:

case 2:

OK, I fixed the '2' problem
when I take the ; from in front of float
I get :

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(6) : warning C4518: 'float ' : storage-class or type specifier(s) unexpected here; ignored
G:\VC++60\ResistancePar\ResistancePar.cpp(6) : error C2146: syntax error : missing ';' before identifier 'Rpar'
G:\VC++60\ResistancePar\ResistancePar.cpp(6) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

ResistancePar.obj - 2 error(s), 1 warning(s)
Like this:

#include <iostream>
#include <cmath>
using namespace std;
int main()

float Rpar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
int quantity;

{

	
	{	
cout << "Enter the quantity of resistors" << endl;
cout << "A maximum of 6 resistors please" << endl;
cin >> quantity;
switch (quantity)
	}

case 1:
cout << " You must enter at least 2";
break;
case 2:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	Rpar = (Rone * Rtwo) / (Rone + Rtwo);
    cout

When I put the ; back in front ;float

I get:

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(9) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

ResistancePar.obj - 1 error(s), 0 warning(s)
:rolleyes:

Three times you've been told not to declare variables between this

int main()

and this

{ // the opening brace of main

Three times you've ignored it. If you implement the suggestions already mentioned in this thread, your errors should be gone.

This:

int main()

;float RPar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
int quantity;

{

should be like this:

int main()
{
   float Rpar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
   int quantity;

It's not that I ignored it, I tried it and it and got tons more errors than before I tried it.

#include <iostream>
#include <cmath>
using namespace std;
int main()



{
float Rpar, Rone, Rtwo, Rthree, Rfour, Rfive, Rsix;
int quantity;
	
		
cout << "Enter the quantity of resistors" << endl;
cout << "A maximum of 6 resistors please" << endl;
cin >> quantity;
switch (quantity)


case 1:
cout << " You must enter at least 2";
break;
case 2:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	Rpar = (Rone * Rtwo) / (Rone + Rtwo);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 3:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	Rpar = (Rone * Rtwo * Rthree) / (Rone + Rtwo + Rthree);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 4:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	Rpar = (Rone * Rtwo * Rthree * Rfour) / (Rone + Rtwo + Rthree + Rfour);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 5:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive) / (Rone + Rtwo + Rthree + Rfour + Rfive);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";
break;
case 6:
	cout << " Enter the value of the first resistor";
	cin >> Rone;
	cout << " Enter the value of the second resistor";
	cin >> Rtwo;
	cout << " Enter the value of the third resistor";
	cin >> Rthree;
	cout << " Enter the value of the fouth resistor";
	cin >> Rfour;
	cout << " Enter the value of the fifth resistor";
	cin >> Rfive;
	cout << " Enter the value of the sixth resistor";
	cin >> Rsix;
	Rpar = (Rone * Rtwo * Rthree * Rfour * Rfive * Rsix) / (Rone + Rtwo + Rthree + Rfour + Rfive + Rsix);
    cout <<"The value of parallel resistance is: " << Rpar << "\n";

	

return 0;
}

Compiling...
ResistancePar.cpp
G:\VC++60\ResistancePar\ResistancePar.cpp(21) : error C2043: illegal break
G:\VC++60\ResistancePar\ResistancePar.cpp(22) : error C2046: illegal case
G:\VC++60\ResistancePar\ResistancePar.cpp(29) : error C2043: illegal break
G:\VC++60\ResistancePar\ResistancePar.cpp(30) : error C2046: illegal case
G:\VC++60\ResistancePar\ResistancePar.cpp(39) : error C2043: illegal break
G:\VC++60\ResistancePar\ResistancePar.cpp(40) : error C2046: illegal case
G:\VC++60\ResistancePar\ResistancePar.cpp(51) : error C2043: illegal break
G:\VC++60\ResistancePar\ResistancePar.cpp(52) : error C2046: illegal case
G:\VC++60\ResistancePar\ResistancePar.cpp(65) : error C2043: illegal break
G:\VC++60\ResistancePar\ResistancePar.cpp(66) : error C2046: illegal case
Error executing cl.exe.

ResistancePar.obj - 10 error(s), 0 warning(s)

Doesn't putting the variable outside the brackets just make them global?
I wouldn't think that it should effect anything, then I am just a greenhorn trying to learn.

:mrgreen:

It's not that I ignored it, I tried it and it and got tons more errors than before I tried it.

That's good. They were hidden by this one previously. Now the compiler can point them out.

Then some more errors that can be fixed by enclosing the statements for the switch within {}.

Doesn't putting the variable outside the brackets just make them global?
I wouldn't think that it should effect anything, then I am just a greenhorn trying to learn.

You didn't put them outside the function so much as in no-man's-land.

All Right!

Now we're talkin. I just didn't understand the {} thing in the earlier post.
I'm still on a learning curve, but I sur appreciate the help here.

I thought the comiler caught all the errors and listed them, but now I see that it sometimes will return before checking all of them. Correct?

Thanks, Guy's :)

BandM

I thought the comiler caught all the errors and listed them, but now I see that it sometimes will return before checking all of them. Correct?

Some errors can cause the whole rest of the program look like a single statement and cut short the number of true errors. Other errors, like a missing semicolon, can produce piles of false error messages.

This article has been dead for over six months. Start a new discussion instead.