#include <stdio.h>
#include <string>
int main(){
float a,b,z,u,r,k;
char f,q,m;
system("color B");
repeat:
printf("Unesite broj a: ");
scanf("%f",&a);
repeatm:
printf("Unesite broj b: ");
scanf("%f",&b);
printf("Unesite funkciju (+,-,*,/): ");
finput:
scanf("%s",&f);
if(f=='+'){
goto zbroj;
}else{
if(f=='-'){
goto razlika;
}else{
if(f=='*'){
goto umnozak;
}else{
if(f=='/'){
goto kolicnik;
}else{
goto _newf;
}
}
}
}
//input of numbers and a check if the value of 'f' is one of the characters +,-,* or /
zbroj:
z=a+b;
printf("-------------------------------------\n");
printf("Zbroj ta dva broja je: ");
printf("%f \n",z);
goto _new;
razlika:
r=a-b;
printf("-------------------------------------\n");
printf("Razlika ta dva broja je: ");
printf("%f \n",r);
goto _new;
umnozak:
u=a*b;
printf("-------------------------------------\n");
printf("Umnozak ta dva broja je: ");
printf("%f \n",u);
goto _new;
kolicnik:
if(b==0){
system("cls");
printf("Ne mozete dijeliti s nulom \n");
goto repeatB;
}else{
k=a/b;
printf("-------------------------------------\n");
printf("Kolicnik ta dva broja je: ");
printf("%f \n",k);
goto _new;
}
//prints results
_newf:
printf("Nevazeca funkcija, upisite ponovo: ");
goto finput;
//loop if 'f' isnt one of +,-,*,/
_new:
printf("-------------------------------------\n");
printf("Novi racun?(y/n) ");
scanf("%s",&q);
system("cls");
goto repeat1;
//asks if i want to exit or go back to start
repeat1:
if(q=='y'){
system("cls");
goto memory;
}else{
if(q=='n'){
goto exit;
}else{
printf("Novi racun? \n");
printf("Molimo upisite y ili n: ");
scanf("%s", &q);
goto repeat1;
}
}
//loops back to start
memory:
printf("Zelite li iskoristits peredhodni rezultat kao broj a?(y/n): ");
scanf("%s", &m);
//asks if i want the previous result as the number 'a'
repeat2:
if(m=='y'){
system("cls");
goto printfa;
}else{
if(m=='n'){
system("cls");
goto repeat;
}else{
printf("Zelite li iskoristits peredhodni rezultat kao broj a? \n");
printf("Molimo upisite y ili n: ");
scanf("%s", &m);
goto repeat2;
}
}
//checks if variable 'm' is either y or n
printfa:
if(f=='+'){
a=z;
}else{
if(f=='-'){
a=r;
}else{
if(f=='*'){
a=u;
}else{
if(f=='/'){
a=k;
}
}
}
}
//this should(?) overwrite the variable 'a'
//why isnt 'a' overwritten with the value of 'z', 'r', 'u' or 'k' here?
printf("Broj a je: %f \n", a);
//here the value of 'a' stays the same as it was before
goto repeatm;
repeatB:
printf("Unesite broj b: ");
scanf("%f",&b);
goto kolicnik;
exit:
system("cls");
system("pause");
return(0);
}
is there any way to overwrite the variable 'a' (without manual input) with one of the values of 'z', 'r', 'u' or 'k'. the result of this code is just a + (or -,*,/) new b (which i manualy input again, but the variable a stays the same as the first input). pleas dont mind the foreign language it just says "input a", "input b", "the result is..", also sorry if the code is messy..