Hi, i'm new to C, and I cannot find the problem, is it somesort of text input failure or what?
Here is the whole program
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <limits.h>
#include <string.h>
int pirma();
int main()
{
//goto START;
START:
;
system("cls"); //clear screen
int a=INT_MAX;
printf("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n");
printf("| Programos veiksmu pasirinkimas: |\n");
printf("|irasykite skaiciu, kurios programos dalies norite|\n");
printf("///////////////////////////////////////////////////\n");
printf("|1 - is dvejetaines i desimtaine |\n");
printf("|2 - is dvejetaines i sesioliktaine |\n");
printf("|3 - is desimtaines i dvejetaine |\n");
printf("|4 - is desimtaines i sesioliktaine |\n");
printf("|5 - is sesioliktaines i dvejetaine |\n");
printf("|6 - is desioliktaines i desimtaine |\n");
printf("|0 - iseiti is programos |\n");
printf("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n");
scanf("%d", &a);
system("cls"); //clear screen
//start of warning if they choose a program that do not exist
if(a>6)
{
int b=0;
printf("Nera tokios programos\n");
printf("Paspauskite 1, kad galetumete is naujo pasirinkti\n");
scanf("%d", &b);
if(b==1)
{
system("cls"); //clear screen
goto START;
}
int c=INT_MAX;
while(c==INT_MAX)
{
printf("Paspauskite 1, kad galetumete is naujo pasirinkti\n");
scanf("%d", &b);
if(b==1)
{
c=1;
system("cls"); //clear screen
goto START;
}
}
}
//end of warning if they choose a program that do not exist
//nuline, jei nori iseiti is programos
if(a==0)
{
char p, y="y";
int lygybe=0;
printf("Ar tikrai norite iseiti is programos?\n");
printf("Jei taip, spauskite y\n");
printf("Jei ne, spauskite n\n");
scanf("%c", &p);
lygybe=strcmp(p, y);
if(lygybe==0)
exit(0);
else
goto START;
}
//pirmoji programa
if(a==1)
{
pirma();
}
return 0;
}
int pirma()
{
int binary=0, bp=0; //bp - isaugojimas pradiniu duomenu
int decimal=0;
int k=0; //pagalbinis skaiciuojant desimtaini
int m=1; //kitas pagalbinis, kuris dides
printf("***********************************************************************************\n");
printf("** Iveskite savo norima dvejetaini koda, kuri noretumete paversti desimtainiu: **\n");
printf("***********************************************************************************\n");
scanf("%d", &binary);
bp = binary;
while (bp > 0)
{
k = bp % 10;
decimal=decimal+k*m;
bp=bp/10;
m=m*2;
}
system ("cls");
printf("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n");
printf("HH Jusu pasirinktas dvejetainis kodas: %d", binary);
printf(" HH\n");
printf("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n");
printf("HH Gautas desimtainis kodas, konvertutoas is dvejetainio: %d", decimal);
printf(" HH\n");
printf("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH\n");
}
But the problem comes when in the start you press 0, and thats where comes scanf I meantioned before
Code:
if(a==0)
{
char p, y="y";
int lygybe=0;
printf("Ar tikrai norite iseiti is programos?\n");
printf("Jei taip, spauskite y\n");
printf("Jei ne, spauskite n\n");
scanf("%c", &p);
lygybe=strcmp(p, y);
if(lygybe==0)
exit(0);
else
goto START;
}