Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. To print two index in a sentence

To print two index in a sentence

Scheduled Pinned Locked Moved C / C++ / MFC
databasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eugene Low
    wrote on last edited by
    #1

    CString isWrong = _T(" is wrong");
    CString andMsg = _T(" and ");

    bool bCorrect\[4\];
    int numOfFalse = 0;
    
    for(int i=0; i<4; i++){
    	bCorrect\[i\] = true;
    	if(arrA\[i\] != arrB\[i\]){
    		bCorrect\[i\] = false;
    		numOfFalse++;
    	}
    }
    
    for(int i=0; i<4; i++){
    	if((bCorrect\[i\] == false) && (numOfFalse == 2))
    	{
    		strRslt.Format("Q%d", i+1);
    		m\_listRslt.AddString(strRslt + isWrong);
    	}
    }
    

    I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?

    L CPalliniC 2 Replies Last reply
    0
    • E Eugene Low

      CString isWrong = _T(" is wrong");
      CString andMsg = _T(" and ");

      bool bCorrect\[4\];
      int numOfFalse = 0;
      
      for(int i=0; i<4; i++){
      	bCorrect\[i\] = true;
      	if(arrA\[i\] != arrB\[i\]){
      		bCorrect\[i\] = false;
      		numOfFalse++;
      	}
      }
      
      for(int i=0; i<4; i++){
      	if((bCorrect\[i\] == false) && (numOfFalse == 2))
      	{
      		strRslt.Format("Q%d", i+1);
      		m\_listRslt.AddString(strRslt + isWrong);
      	}
      }
      

      I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      if((bCorrect[i] == false) && (numOfFalse == 2))
      {
      strRslt.Format("Q%d%sQ%d%s", i, andMsg, i + 1, isWrong);
      printf("%s\n", strRslt);
      }

      E 1 Reply Last reply
      0
      • L Lost User

        if((bCorrect[i] == false) && (numOfFalse == 2))
        {
        strRslt.Format("Q%d%sQ%d%s", i, andMsg, i + 1, isWrong);
        printf("%s\n", strRslt);
        }

        E Offline
        E Offline
        Eugene Low
        wrote on last edited by
        #3

        Assume the false value is random assign in the array. The program will check by itself which index has a 'false' then print out the index number. For example, index 0 and 3 have 'false', then print out "Q1 and Q4 is wrong"

        L 1 Reply Last reply
        0
        • E Eugene Low

          Assume the false value is random assign in the array. The program will check by itself which index has a 'false' then print out the index number. For example, index 0 and 3 have 'false', then print out "Q1 and Q4 is wrong"

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Try this, which keeps track of the number that are false:

          strRslt = "";
          int wrong = 0;
          for(int i=0; i<4; i++)
          {
          if(bCorrect[i] == false)
          {
          if (wrong++ > 0)
          strRslt.AppendFormat("%s", andMsg);
          strRslt.AppendFormat("Q%d", i + 1);
          }
          }
          if (wrong > 0)
          {
          strRslt.AppendFormat("%s", isWrong);
          printf("%s\n", strRslt);
          }

          1 Reply Last reply
          0
          • E Eugene Low

            CString isWrong = _T(" is wrong");
            CString andMsg = _T(" and ");

            bool bCorrect\[4\];
            int numOfFalse = 0;
            
            for(int i=0; i<4; i++){
            	bCorrect\[i\] = true;
            	if(arrA\[i\] != arrB\[i\]){
            		bCorrect\[i\] = false;
            		numOfFalse++;
            	}
            }
            
            for(int i=0; i<4; i++){
            	if((bCorrect\[i\] == false) && (numOfFalse == 2))
            	{
            		strRslt.Format("Q%d", i+1);
            		m\_listRslt.AddString(strRslt + isWrong);
            	}
            }
            

            I want to print out something like Q1 and Q2 is wrong. Can anyone teach me ?

            CPalliniC Offline
            CPalliniC Offline
            CPallini
            wrote on last edited by
            #5

            Try (not tested, but you get the idea)

            bool bAlreadyIncorrect = false;
            for(int i=0; i<4; i++)
            {
            if ( bCorrect[i] == false )
            {
            if ( bAlreadyIncorrect )
            m_listRslt.AddString(" and ");

            strRslt.Format("Q%d", i+1);
            m\_listRslt.AddString(strRslt);
            
            bAlreadyIncorrect = true;
            

            }
            }

            if (bAlreadyIncorrect)
            m_listRslt.AddString( " is wrong");

            "In testa che avete, Signor di Ceprano?" -- Rigoletto

            In testa che avete, signor di Ceprano?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups