Friday, July 31, 2009

Question about c++?

#include %26lt;conio.h%26gt;// needed for getch


#include %26lt;iostream.h%26gt;//needed for cout and cin messages


#include %26lt;iomanip.h%26gt;//





void startup();


void method();


int a2r (int Num);


int main()


{


startup();


method();


a2r (int Num);


getch();


return 0;


}





void startup()


{


cout%26lt;%26lt;""%26lt;%26lt;'\n';


cout%26lt;%26lt;"jan ,2008"%26lt;%26lt;'\n';


cout%26lt;%26lt;"pg-108 ex- pro-6.3"%26lt;%26lt;'\n';


cout%26lt;%26lt;""%26lt;%26lt;'\n';


}








int a2r (int Num)


{


int Th, Hu, Ten, Fiv, One;


char Roman1[20];


char Roman2[5];


char Roman3[5];


char Roman4[5];











Th = Num / 1000;


Num = Num - (1000*Th);


Hu = Num/ 100;


Num = Num - (100*Hu);


Ten = Num / 10;


Num = Num - (10*Ten);


Fiv = Num / 5;


Num = Num - (5*Fiv);


One = Num / 1;


Num = Num - (1*One);








while (1 to th)


{


cout%26lt;%26lt;"M";


}





while (1 to Hu)


{


cout%26lt;%26lt;"C";


}





while (1 to Ten)


{


cout%26lt;%26lt;"X";


}





while (1 to Fiv)


{


cout%26lt;%26lt;"V";


}


while (1 to One)


{


cout%26lt;%26lt;"I";


}














}


void method()


{


char roman[20];


int arabic;





cout%26lt;%26lt;"Arabic to numeral\n";


cout%26lt;%26lt;"Please enter a number between 1 to 4999\n";


cin%26gt;%26gt;arabic;


while (arabic%26gt;4999 || arabic%26lt;1)


{


cout%26lt;%26lt;"Please enter a number between 1 and 4999:\n");


cin%26gt;%26gt;arabic;


}


a2r(arabic);


}

Question about c++?
There are 3 basic loop types:





(1) for





for(start condition; end condition; increment)


{


do something;


}





(2) while


while(some condition is true)


{


do something;


}





3) do...while





do


{


do somethingl


} while (condition is true)





Note that the difference between while and do...while is that do...while will always execute at least once.





It looks like you need a for loop where you think you need a while loop. E.G





for (int i = 1; i = Fiv; i++)


{


cout%26lt;%26lt;"V";


}
Reply:i would help but the last time i did c++ was 2 years ago
Reply:i dont know about that...
Reply:while loops dont have a "to" statement.





For loops do, like





for(int i=0;i%26lt;10;i++){


cout%26lt;%26lt;"Hello";


}


No comments:

Post a Comment