請不要打消這個問題..我對C++很陌生,真的很想了解我工作的代碼。困惑於我的代碼如何工作,並想了解其中的邏輯
// bintodec.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main(){
string inp;
int dec = 0;
char base;
cout << "Input a number: ";
cin >> inp;
cout << "Input the base your number is in: ";
cin >> base;
for(int i = inp.length()-1, j = 0; i >= 0; i--, ++j) dec += (inp[i]-48) * pow((float)base-48, j);
cout << "Your number in base 10 is: " << dec <<endl;
system("pause");
return 0;
}
我真的很想理解這個FOR LOOP如何運行INPUT NUMBER和BASE,然後得到答案。
所以可以說我輸入110 BASE 2 PRINT:6
*如何for循環都做
的感謝!
請搜索並閱讀C++教程。 –
很難說出你在問什麼。你只是想知道'for'循環做了什麼?這個問題很可能會被封閉,但原因只是在不知道自己不明白的情況下回答是不可能的。 –
@BrendanLong「我真的很想理解這個FOR LOOP如何運行INPUT NUMBER和BASE,然後得到答案。」不可能? –