#include <iostream>
#include <iomanip>
#include <string>
#include <ios>

using std::string;
using std::streamsize;
using std::setprecision;
using namespace std;



int main()
{
	double Ib,I,V,P,F,pf,In;
	unsigned short int type;
	cout<<"Please select the type of power supply\n";//Allows the user to choose between single or three phase
	cin>>type;
	switch(type)
	{
	case 1:cout<<"You have chosen a single phase power supply\n";
		break;
	case 2:cout<<"You have chosen a three phase power supply\n";
		break;
	default:cout<<"Invalid choice please try agin\n";
		break;
	}
	cout<<"Please enter the value of I\n";//the value of the load current
	cin>>I;
	cout<<"Please enter the value of V\n";//the value of the input volatge
	cin>>V;
	cout<<"Please enter the value of F\n";//the frequency
	cin>>F;
	cout<<"Please enter the value of the power factor\n";//the power factor
	cin>>pf;
	
	
	if(type=1)
	{
		cout<<"Ib in Single phase is\n" << setprecision(4)
		<<(V*I)/V/I/pf
		<<setprecision(4)<<endl;
	
	else 
		cout<<"Ib in Three phase is\n" << setprecision(4)
		<<(V*I)/(1.732*V*pf)
		<<setprecision(4)<<endl;
	}

	
	
	return 0;
}

Recommended Answers

All 4 Replies

You need to use { and } between the if and else statements

if( something )
{
   // code here
}
else
{
   // more code here
}

tried it out but it displays the current in single phase when i need the current in 3 phase

>>if(type=1)

Use == operator, not the assignment = operator.

1) = means "assign the following value". ==, which is what you should almost always be using in the parentheses part of if statements, means "equivalent to" and is used for comparisons.

2) When the code following your if (but before your else) statement consists of more than 1 line, those lines of code must be contained in curly braces (not the actual if line, just the lines following it). The same applies to the code after your else statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.