little_greg Posted September 21, 2009 Report Share Posted September 21, 2009 помогите найти ошибку, не высчитывается сумма. программа должна записывать числа в массив, если введено не число - то программа выходит из цикла и высчитывает сумму. #include <iostream>#include <cctype>using namespace std;const int size = 10;int main(){double donation[size];double average = 0.0;double num;cout << "enter 10 donation. for stop enter a letter.\n";int i;for (i = 0; i < size; i++){ cin >> num; if (isdigit(num)) donation[i] = num; }double total = 0.0;for (int j = 0; j < i; j++) total += donation[j];cout << total;system("pause");return 0;} Link to comment Share on other sites More sharing options...
little_greg Posted September 21, 2009 Author Report Share Posted September 21, 2009 #include <iostream> #include <cctype> using namespace std; const int size = 10; int main() { double donation; double average = 0.0; double num; cout << "enter 10 donation. for stop enter a letter.\n"; int i = 0; cin >> num; while (isdigit(num) && i < size) { donation = num; cin >> num; i++; } double total = 0.0; for (int j = 0; j < i; j++) total += donation[j]; cout << total; system("pause"); return 0; } #include <iostream> #include <cctype> using namespace std; const int size = 10; int main() { double donation; double average = 0.0; double num; cout << "enter 10 donation. for stop enter a letter.\n"; int i = 0; cin >> num; while (isdigit(num) && i < size) { donation = num; total += donation cin >> num; i++; } double total = 0.0; for (int j = 0; j < i; j++) total += donation[j]; cout << total; system("pause"); return 0; } блин там выше не тот код #include <iostream> #include <cctype> using namespace std; const int size = 10; int main() { double donation; double average = 0.0; double num; cout << "enter 10 donation. for stop enter a letter.\n"; int i = 0; cin >> num; while (isdigit(num) && i < size) { donation = num; total += donation cin >> num; i++; } double total = 0.0; for (int j = 0; j < i; j++) total += donation[j]; cout << total; system("pause"); return 0; } запарился!!! где вот в этом коде ошибка? заранее спасибо #include <iostream>#include <cctype>using namespace std;const int size = 10;int main(){double donation[size];double average = 0.0;double num;cout << "enter 10 donation. for stop enter a letter.\n";int i = 0;cin >> num;while (isdigit(num) && i < size){ donation[i] = num; total += donation[i] cin >> num; i++; }double total = 0.0;for (int j = 0; j < i; j++) total += donation[j];cout << total;system("pause");return 0;} Link to comment Share on other sites More sharing options...
Тролль Posted September 21, 2009 Report Share Posted September 21, 2009 little_greg: Читай сообщения компилятора. Уже навскидку видно, что после total += donation нет точки с запятой, не говоря уже о том, что total определена и инициализирована уже после ее использования. Кроме того, digit и number в английском разные вещи - цифра и число: is digit проверяет, является ли введенный символ цифрой, а для проверки, являются ли введенные данные числом, проверяется мнение cin об этом запросом cin.fail(), это возвращает true при ошибке. Link to comment Share on other sites More sharing options...
little_greg Posted September 21, 2009 Author Report Share Posted September 21, 2009 спасибо Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now