c++ - need help to incorporate this 2nd function into my program -


hi i'm making program ask user enter integer , spit out in roman numerals. had working roman numeral part work couldn't loop program. have program looped can't roman numeral function work. program executes it's if function1 doesn't exist , dont know how main function use it. have keep user interaction in main function. want cout << roman << endl; line spit out integer in roman numerals it's not working. 2nd assignment ever appreciated! thanks

#include <iostream> #include <string>   using namespace std; string roman; int integer; int num;  char answer;  int main() {   while (true)   {     cout << "enter integer " << endl;     cin >> integer;     cout << roman << endl;     cout << "convert (y/n)? " << endl;     cin >> answer;     if (answer == 'n' || answer == 'n')         break;   } }  int function1() {   if ((integer >= 4000) || (integer <= 0))   {     cout << endl << "invalid integer" << endl;   }   //3286   else   {     if (integer >= 1000)     {         num = (integer / 1000);          (int = 0; < num; i++)         {             roman += 'm';         }         integer %= 1000;         // care ^^^     }     // 286     if (integer >= 100)     {         num = (integer / 100);          if (num == 9)         {             roman += "cm";         }         else if (num >= 5)         {             roman += 'd';              (int = 0; < num - 5; i++)             {                 roman += 'c';             }         }         else if (num == 4)         {             roman += "cd";         }         else if (num >= 1)         {             (int = 0; < num; i++)             {                 roman += 'c';             }         }         integer %= 100;     }      // 86     if (integer >= 10)     {         num = (integer / 10);          if (num == 9)         {             roman += "xc";         }         else if (num >= 5)         {             roman += 'l';              (int = 0; < num - 5; i++)             {                 roman += 'x';             }         }         else if (num == 4)         {             roman += "xl";         }         else if (num >= 1)         {             (int = 0; < num; i++)             {                 roman += 'x';             }         }         integer %= 10;         // 6      }      if (integer >= 1)     {         num = integer;          if (num == 9)         {             roman += "ix";         }         else if (num >= 5)         {             roman += "v";              (int = 0; < num - 5; i++)             {                 roman += 'i';             }         }         else if (num == 4)         {             roman += "iv";         }         else if (num >= 1)         {             (int = 0; < num; i++)             {                 roman += 'i';             }         }     }       cout << "--> " << roman << endl;  } system("pause"); return 0; } 

you need call function1, example:

while (true) {     cout << "enter integer " << endl;     cin >> integer;     function1();     cout << roman << endl;     cout << "convert (y/n)? " << endl;     cin >> answer;     if (answer == 'n' || answer == 'n')         break; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -