プログラムはループを正しい時間実行するので、私たちは部門が動作していることを知っていますが、文字列変数 "result"に含まれるものの出力を得ることはできません。どんな助け?私のプログラムはループを正しい回数だけ実行しますが、文字列変数は見えませんか?
#include <iostream>
#include <string>
using namespace std;
int main()
{
int base,decimal,remainder;
string result;
cout <<"Welcome to the Base Converter. Please enter in the requested base from 2-16"<<endl;
cout <<"and an integer greater than or equal to zero and this will convert to the new base."<<endl
do
{
cout <<"Please enter the requested base from 2-16:"<<endl;
cin >>base;
}while (base<2 || base>16);
do
{
cout <<"Please enter the requested integer to convert from base 10:"<<endl;
cin >>decimal;
}while (decimal<0);
do
{
decimal=decimal/base;
remainder=decimal%base;
if (remainder<=9)
{
string remainder;
result=remainder+result;
}
else
{
switch(remainder)
{
case 10:
{
result="A"+result;
}
私のスイッチにはいくつかのケースがありますが、問題は変数宣言または文字列クラスのどこかにあると思います。明らかな解決策はありますか?
そして、一度に1行ずつコードを実行し、すべての変数を調べたときに、デバッガでどのような観測をしましたか? –
'string remainder;'の目的は何ですか?私はあなたの整数の残りの同じ名前の残りの名前の文字列を宣言することを意味します。 – drescherjm
C++にはまったく新しかったですが、デバッガでは何も普通のようには思えませんでしたが、すべてがきれいにコンパイルされました。 – Zach