Jump to content

Циклы в C++ (DEV C++)


Recommended Posts

помогите найти ошибку, не высчитывается сумма. программа должна записывать числа в массив, если введено не число - то программа выходит из цикла и высчитывает сумму.

#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

#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

little_greg:

Читай сообщения компилятора. Уже навскидку видно, что после total += donation нет точки с запятой, не говоря уже о том, что total определена и инициализирована уже после ее использования.

Кроме того, digit и number в английском разные вещи - цифра и число: is digit проверяет, является ли введенный символ цифрой, а для проверки, являются ли введенные данные числом, проверяется мнение cin об этом запросом cin.fail(), это возвращает true при ошибке.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...