Mając zamiar wzbogacić mój program program przeliczający masy o pętle wyświetlaną w przypadku nieprawidłowej liczby typu char program przestał wykonywać instrukcje switch linijka od 98 do 105 .
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
using namespace std;
int war1,znowu;
long double x,y;
char wybor ;
char prze;
int main()
{
cout << "Witaj w aplikacji przelicznik !"<<endl;
/// do
/// {
do
{
cout << "Co chcesz przeliczy\206 ???" << endl;
cout << endl;
cout << endl;
cout << endl;
cout << " MENU " << endl;
cout << "--------------------" << endl;
cout << "1. Masae" << endl;
cout << "2. Dlugo\230\206" << endl;
cout << "3. Czas" << endl;
cout << "4. Wyj\230cie" << endl;
cout << "Wyb\242r:";
wybor=_getch();
if(wybor>'4')
{
cout << endl;
cout << endl;
cout << "Nie ma takiej opcji!"<<endl;
cout << "Spróbuj ponownie!"<<endl;
cout << endl;
system("pause");
system("cls");
}
}
while (wybor>'4' );
system("cls");
switch (wybor)
{
case '1':
{
do
{
cout << "Z jakiej jednostki chcesz przelicza\206" << endl;
cout << endl;
cout << "MENU PRZELICZNIKA MAS" << endl;
cout << "---------------------" << endl;
cout << "1. Gramy" << endl;
cout << "2. Dekagramy" << endl;
cout << "3. Kilogramy" << endl;
cout << "4. Tony" << endl;
cout << "Wyb\242r: ";
cin >> war1;
if (war1>4)
{
cout << endl;
cout << "Nie ma takiej opcji!"<<endl;
cout << "Spróbuj ponownie!"<<endl;
cout << endl;
system("pause");
system("cls");
}
}
while(war1>4);
cout << "Podaj warto\230\206: ";
cin >> x;
system("cls");
//////////////////////////////////////////////////
do
{
cout << "Na co chcesz przelicza\206" << endl;
cout << endl;
cout << "MENU PRZELICZNIKA MAS" << endl;
cout << "---------------------" << endl;
cout << "1. Gramy" << endl;
cout << "2. Dekagramy" << endl;
cout << "3. Kilogramy" << endl;
cout << "4. Tony" << endl;
cout << "Wyb\242r:";
prze=_getch();
if (prze>'4')
{
cout << endl ;
cout << "Nie ma takiej opcji!"<<endl;
cout << "Spróbuj ponownie!"<<endl;
cout << endl;
system("pause");
system("cls");
}
}
while (prze>4);
system("cls");
switch (prze)
{
case 1:
{
if (war1==1)
{
cout <<x<<"g = "<<x<<"g";
break;
}
else if (war1==2)
{
y=x*10;
cout <<x<<"dag = "<<y<<"g";
break;
}
else if (war1==3)
{
y=x*1000;
cout <<x<<"kg = "<<y<<"g";
break;
}
else if (war1==4);
{
y=x*1000000;
cout <<x<<"t = "<<y<<"g";
break;
}
system("pause");
}
case '2':
{
if (war1==1)
{
y=x/10;
cout <<x<<"g = "<<y<<"dag";
break;
}
else if (war1==2)
{
cout <<x<<"dag = "<<x<<"dag";
break;
}
else if (war1==3)
{
y=x*100;
cout <<x<<"kg = "<<y<<"dag";
break;
}
else if (war1==4);
{
y=x*100000;
cout <<x<<"t = "<<y<<"dag";
break;
}
}
}
}
return 0;
Edit 1. poprawiłem kod na kod z C++ wcześniej najwidoczniej zapisał mi się jako kod z HTML-a