Skocz do zawartości

Zastosowanie "if" "else" w programie w językuC++


Refeere

Polecane posty

Nie znam tego błędu programu. kto pomoże

 

oto program:

 

#include <iostream>

using namespace std;

 

int main() {

cout << "Program napisany przez Refeere`go" << endl // Informacja o twórcy

<< "Zadaniem jest obliczac % punktow ze sprawdzianu i zmiany na ocene" << endl; // Informacja o programie

 

cout << "Podaj maxymalna liczbe punktow do uzyskania na sprawdzianie" << endl; // Informacja

int x; // Deklaracja iloœci max. punktów do uzyskania na sprawdzianie

cin >> x; // Wypisujemy maxymaln¹ liczbe punktów

 

cout << "Podaj uzyskana liczbe punktow ucznia ze sprawdzianu" << endl; // Informacja

int y; // Deklaracja iloœci zdobytych punktów

cin >> y; // Wypisanie iloœci punktów

 

cout << "Uzyskana ocena przez ucznia to:" << endl;

 

 

if (x / y =< 0,39);

cout << "Ocena to 1" << endl;

else (x / y >= 0,40)

cout << "Ocena to -2" << endl;

else (x / y =< 0,43)

cout << "Ocena to -2" << endl;

else (x / y >= 0,44)

cout << "Ocena to 2" << endl;

else (x / y =< 0,48)

cout << "Ocena to 2" << endl;

else (x / y >= 0,49)

cout << "Ocena to +2" << endl;

else (x / y =< 0,51)

cout << "Ocena to +2" << endl;

else (x / y >= 0,52)

cout << "Ocena to -3" << endl;

else (x / y =< 0,57)

cout << "Ocena to -3" << endl;

else (x / y >= 0,58)

cout << "Ocena to 3" << endl;

else (x / y =< 0,64)

cout << "Ocena to 3" << endl;

else (x / y >= 0,65)

cout << "Ocena to +3" << endl;

else (x / y =< 0,70)

cout << "Ocena to +3" << endl;

else (x / y >= 0,71)

cout << "Ocena to -4" << endl;

else (x / y =< 0,76)

cout << "Ocena to -4" << endl;

else (x / y >= 0,77)

cout << "Ocena to 4" << endl;

else (x / y =< 0,84)

cout << "Ocena to 4" << endl;

else (x / y >= 0,85)

cout << "Ocena to +4" << endl;

else (x / y =< 0,90)

cout << "Ocena to +4" << endl;

else (x / y >= 0,91)

cout << "Ocena to -5" << endl;

else (x / y =< 0,95)

cout << "Ocena to -5" << endl;

else (x / y >= 0,96)

cout << "Ocena to 5" << endl;

else (x / y =< 0,99)

cout << "Ocena to 5" << endl;

else (x / y = 1,00)

cout << "Ocena to 6" << endl;

 

system ("PAUSE");

return 0;

}

 

 

gdzie jest błąd. Pomoże ktoś prosze

Link do komentarza
Udostępnij na innych stronach

[..]

gdzie jest błąd. Pomoże ktoś prosze

x i y to zmienne całkowite, dzielenie ich to też liczba całkowita.....

 

proponowana poprawka:

 

double z;//dodaj zmienną
[...]
z = ((double)x)/y;
[...]
//porównuj
if (z =< 0,39);[/font]
cout << "Ocena to 1" << endl;[/font]
else if  (z >= 0,40)//po else jesli masz jakis warunek to nie sam warunek, ale jeszcze if musi być![/font]

Można by bez dodatkowej zmiennej, ale tak będzie działało szybciej.

 

Acha - pomijam też to, czy warunki wstawione mają sens (nie mają)

Link do komentarza
Udostępnij na innych stronach

  • 1 month later...
  • 1 month later...

Zarchiwizowany

Ten temat jest archiwizowany i nie można dodawać nowych odpowiedzi.

×
×
  • Utwórz nowe...