A więc problem jest taki. Mam kod źródłowy programu, w którym występuje błąd, którego nie umiem wyeliminować. Jestem jeszcze początkującym programistą, więc robię wiele błędów. Oto kod (po angielsku, bo cały system mam po angielsku więc nie pasowałby mi polski program):
#include <iostream>
#include <cstdio>
using namespace std;
void text_to_number();
void number_to_text();
int main()
{
short what_to_do;
char try_again[2];
do
{
cout << "What would you like to do: " << endl;
cout << "\t" << "1. Translate from text to numbers" << endl;
cout << "\t" << "2. Translate from numbers to text" << endl;
cin >> what_to_do;
getchar();
switch (what_to_do)
{
case 1: text_to_number();
break;
case 2: number_to_text();
break;
default: cout << "Wrong choice. Try again? [Yes/ else = quit]" << endl;
cin.get(try_again, 1);
}
} while((try_again[0] == 'Y') || (try_again[0] == 'y')); //in try_again only first character matters, becouse of get.cin( ,1)
return 0;
}
void text_to_number()
{
char text_to_be_translated[501];
cout << "\t\t\t\tTRANSLATE FROM TEXT TO NUMBERS:"<< endl << endl;
cout << "Enter text to be translated:" << endl;
cin.get(text_to_be_translated, 500);
cout <<"This is translated text: " << endl;
for (int i=0; text_to_be_translated[i] != 0 ; i++)
cout << int(text_to_be_translated[i]) << " ";
cout << endl;
}
void number_to_text()
{
short number_to_be_translated[501], continuation=10 , how_many_letters=1;
cout << "\t\t\t\tTRANSLATE FROM NUMBERS TO TEXT:" << endl << endl;
for (int i=0; (continuation == 10 ) && (i != 500) ; i++) //ENTER equals 10 in ASCII. __Tutaj jest problem.__
{
cout << "Enter number no. " << i+1 << " : " << endl;
cin >> number_to_be_translated[i];
getchar();
cout << "Continue? [press ENTER to continue / else = quit]: ";
cin >> continuation;
getchar();
how_many_letters ++;
}
how_many_letters --;
for (int i=0; i < how_many_letters; i++)
{
cout << char(number_to_be_translated[i]);
}
cout << endl;
}
zadaniem programu jest tłumaczenie tekstu/liczb w ASCII. Z góry dziękuję Wam za pomoc :)