im having trouble with my if else statement, it shows error:'else without previous 'if'.i would greatly appreciate comments and suggestions.thanks y'all.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
char choice,ans;
int a; //process input
cout<<"\nYOU HAVE CHOSEN THE FIRST-COME,FIRST-SERVE ALGORITHM!\n";
cout<<"PLEASE ENTER TOTAL NUMBER OF PROCESS\n";
cout<<"[EXAMPLE: P1,P2 = 2 || P1,P2,P3 = 3 ]\n=";
cout<<"\n\nTHE AVERAGE WAITING TIME\n="<<avwt;
cout<<"\nTHE AVERAGE TURN-AROUND TIME\n="<<avtat;
cout<<"\n\n\nCONTINUE?\n(y)=YES || (n)=NO.\n=";
cin>>ans;
cout<<"\n\n\nCONTINUE?\n(y)=YES || (n)=NO.\n=";
cin>>ans;
return 0;
}
else (choice == 'b' || choice == 'B');
{
cout<<"\nYOU HAVE CHOSEN THE SHORTEST JOB FIRST ALGORITHM!\n";
cout<<"PLEASE ENTER TOTAL NUMBER OF PROCESS\n";
cout<<"[EXAMPLE: P1,P2 = 2 || P1,P2,P3 = 3 ]\n=";
cin>>a;
float total,wait[a];
float p[a],amwaiting=0,waiting=0;
int process;
int stack[a];
float burst[a],arrival[a],amburst,temp[a],top=a,priority[a];
int x;
for(x=0;x<a;x++)
{
p[x]=x;
stack[x]=x;
cout<<"ARRIVAL TIME = ";
cin>>arrival[x];
cout<<"BURST TIME = ";
cin>>burst[x];
cout<<"POSITION= ";
cin>>priority[x];
for(int z=0;z<top-1;z++) //last element inserted in the stack
{
if((priority[stack[0]]>priority[stack[z+1]]) && (arrival[stack[z+1]] <= x+1))
{
int t=stack[0];
stack[0]=stack[z+1];
stack[z+1]=t;
}
}
}
}
cout<<"\n\nTHE AVERAGE WAITING TIME \n= "<<waiting/a;
float tu=(amburst+waiting)/a;
cout<<"\nTHE AVERAGE TURN-AROUND \n= "<<tu;
cout<<"\n\n\nCONTINUE?\n(Y)=YES || (N)=NO.\n=";
cin>>ans;
system("CLS");
cin>>a;
float total,wait[a];
float p[a],amwaiting=0,waiting=0;
int process;
int stack[a];
float burst[a],arrival[a],amburst,temp[a],top=a,priority[a];
You can not easily populate a C-style array with a variable like this. It needs to be a constant value.
Your second issue: I'm going to paste back your formatted if/else code, but remove the code from inside them so you can see the if else's more clearly:
this is an assignment for my class.im still a little lost at this.i am sorry,but what do you mean by populating it with constant values?
and i tried removing the code from my if/else, and i still don't get the part where i went wrong.lastly am i right that else if statements cant have conditions in them?