Oct 15, 2010 at 7:19am UTC
I'm just starting out with working with C++ and I was trying out stuff with 'if/else' and 'for' loop statements.
I'm trying to use the 'for' statement as a way around adding a lot of variables, etc for each of the 6 outputs.
Can a 'for' loop statement be placed inside an 'if/else' statement?
Could only find vise-versa everywhere else -> 'if inside the for'.
Here's basically what I have so far:
char x;
string contractorNumCW[]={"Contractor #1","Contractor #2","Contractor #3"};
double bidofferCW[]={39.95,34.50,43.95}, totalbidCW[3];
char g;
string contractorNumCP[]={"Contractor #1","Contractor #2","Contractor #3"};
double bidofferCP[]={39.95,34.50,43.95}, totalbidCP[3];
cout<<"Price options for chairs:";
if(yesno<2)
{
for(char x=0; x<3; x++)
totalbidCP[x] = bidofferCP[x] * chairnumP;
cout<<endl <<"CHAIR CONTRACTOR ID: BID OFFER: TOTAL BID PRICE:" <<endl;
for(char x=0; x<3; x++)
cout<<" "<<contractorNumCP[x]<<" $"<<bidofferCP[x]<<" $"<<fixed<<setprecision(2)<<totalbidCP[x]<<endl;
}
else
{
for(char g=0; g<3; g++)
totalbidCW[g] = bidofferCW[g] * chairnumW;
cout<<endl <<"CHAIR CONTRACTOR ID: BID OFFER: TOTAL BID PRICE:" <<endl;
for(char g=0; g<3; g++)
cout<<" "<<contractorNumCW[g]<<" $"<<bidofferCW[g]<<" $"<<fixed<<setprecision(2)<<totalbidCW[g]<<endl;
}
As of right now I can only get it to show the first set of values to show up.
So - What am I doing wrong? and can this to even work?
Oct 15, 2010 at 7:25am UTC
wow. figured it out. feel like an idiot -
just changed the "(yesno<2)" to "(yesno >=2)"
AND
"else" to "else if (yesno<2)"