if else doesnt work

Hello, i just can't figure it out by my self...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
   int i = 7;
   string P[25][25];
   for (int n = 0; n < i; n++){
     for (int m = 0; m < i; m++){
       if(P[n][m].compare("p") == 0){
         Changes(n, m, i);
       }
     }
   }

 Class::Changes(int n, int m, int i){
   for (int k = 0; k < i; k++){
     if ((k != n) || (k == 6)) {
       cout << "success";
     }
     else {
       cout << "failure";
     }
   }
 }


Line if ((k != n) || (k == 6)) doesnt work, it always points to else. If i use only one if (k != n) { or if (k == 6) { it partialy works, so it doesnt make any sence to me... Could someone please help me?
P. S. 2D array P looks like this:

0 p p p 1000 p 1000
1000 0 1000 1000 1000 p p
1000 1000 0 1000 p 1000 p
1000 1000 p 0 p 1000 1000
1000 1000 1000 1000 0 1000 p
1000 1000 1000 1000 1000 0 p
1000 1000 1000 1000 1000 1000 0
Last edited on
The code does exactly what you told it to do; I think your reasoning/logic is wrong.
Why would you have a for() loop inside Changes()?

The if() portion will execute in all cases except where k == n and neither value is 6.
// This is the header file i created

#include<iostream>
using std::cout;
using std::endl;

class GradeBookInterface
{
public:
GradeBookInterface(string);
void setCourseName(string);
string getCourseName();
void dispMessage();
private:
string courseName;
};
//this is the source file that enables the interface
#include <iostream>
using std::cout;
using std::endl;

#include<string>
using std::string;

#include "GradeBookInterface.h"

GradeBookInterface::GradeBookInterface(string name)
{
setCourseName(name);
}

void GradeBookInterface::setCourseName(string name)
{
courseName = name;
}

string GradeBookInterface::getCourseName()
{
return courseName;
}

void GradeBookInterface::dispMessage()
{
cout<<"Welcome to the grade book for\n"<<getCourseName()<<"!"<<endl;
}

//the main source file
#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

#include "GradeBookInterface.h"

int main()
{
GradeBookInterface gbi("CS101 intro to C++ programming");
GradeBookInterface gbi2("CS102 Data Structures in C++");

cout<<"\nGrade book 1 created for course "<<gbi.getCourseName()
<<"\nGrade book 2 created for course "<<gbi2.getCourseName()
<<endl;

return 0;
//when i try to compile that this is the error i get

out:GradeBookInterface3.exe
radeBookInterface3.obj
radeBookInterface3.obj : error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<c
ar> > __thiscall GradeBookInterface::getCourseName(void)" (?getCourseName@GradeBookInterface@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@s
d@@XZ) referenced in function _main
radeBookInterface3.obj : error LNK2019: unresolved external symbol "public: __thiscall GradeBookInterface::GradeBookInterface(class std::basic_string<char,st
uct std::char_traits<char>,class std::allocator<char> >)" (??0GradeBookInterface@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) refer
nced in function _main
radeBookInterface3.exe : fatal error LNK1120: 2 unresolved externals
Topic archived. No new replies allowed.