-1
내가 (< < "순위"cout을 < < 합 + 1 < < ENDL) 6 마지막 줄을 넣어
는 합계가 선언되지 않았 음을 말한다 루프 외부 이 범위. 코드는 바로 다음과 같습니다 :루프 외부에서 합계를 인쇄하려면 어떻게해야합니까? 나는 세계 및 지역 변수의 감속에 약간의 실수가 있다고 생각
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace::std;
int main() {
string input;
cout << "Don't enter repetitive alphabet word \n" << "Enter a word : ";
getline(cin, input);
vector<char> myVector(input.begin(), input.end());
vector<char> myVector2(input.begin(), input.end());
sort(myVector2.begin(), myVector2.end());
if(myVector2 == myVector){
cout << "rank : 1";
}
else{
for (int i = 0; i < myVector2.size(); i++){
//cout << myVector2[i];
}
cout << endl;
int q = 0, value = 1, w = 1;
while(q < myVector.size()){
int k = 0, temp = 0, sum, value = 1, w = 1;
while(k < myVector2.size()){
while(myVector2[k] != myVector[q] && k < myVector2.size()){
while(w < myVector2.size()){
value = value * w ;
w++;
}
k++;
}
temp = value * (k);
break;
}
sum = sum + temp;
myVector2.erase(myVector2.begin()+k);
/* for(int j = 0; j < myVector2.size(); j++){
cout << myVector2[j];
}*/
cout << "rank : " << sum + 1 << endl;
q++;
}
}
}
내가 6 마지막 줄에 인쇄 할 방법 : < < cout을 "순위"< < 합 + 1 < < ENDL을; 루프 바깥에 이 있습니까? 이유를 설명하십시오.
문제는 'sum'이 루프 내에서 선언된다는 것입니다. 선언문을 위로 움직이십시오. – alexeykuzmin0
변수'sum'을 루프 외부에서도 정의 하시겠습니까? –
또한'sum' 변수는 사용하기 전에 초기화되지 않으므로'sum + temp' 할 때 * 동작이 정의되지 않았습니다. –