1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

C calc problem

Discussion in 'C' started by fsakalos, May 14, 2007.

Thread Status:
Not open for further replies.
  1. fsakalos

    fsakalos New Member

    Joined:
    May 14, 2007
    Messages:
    16
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Slovakia
    Code:
    #include <stdio.h>
    int main()
    {
    int letter;
    printf("Vyber si + alebo - alebo * alebo 2(druha mocnina): ");
    letter = getchar();
    	if(letter == '+'){
    		float sucet, citatel, menovatel;
    			printf("Zadaj scitanec: ");
    			scanf("%g", &citatel);
    			printf("Zadaj scitanec: ");
    			scanf("%g", &menovatel);
    			sucet = citatel + menovatel;
    			printf("Vysledok je: %g\n", sucet);
    			return 0;
    	}
    	else if(letter == '-'){
    		float rozdiel, odcitatel, odcitanec;
    			printf("Zadaj odcitatel: ");
    			scanf("%g", &odcitatel);
    			printf("Zadaj odcitanec: ");
    			scanf("%g", &odcitanec);
    			rozdiel = odcitatel - odcitanec;
    			printf("Vysledok je %g\n", rozdiel);
    	return 0;
    	}
    	else if(letter == '*'){
    		float nasobok1, nasobok2, sucin;
    			printf("Zadaj prvy nasobok: ");
    			scanf("%g", &nasobok1);
    			printf("Zadaj druhy nasobok: ");
    			scanf("%g", &nasobok2);
    			sucin = nasobok1 * nasobok2;
    			printf("Vysledok je %g\n", sucin);
    	return 0;
    	}
    	[COLOR=Red]else if(letter == '2'){
    		int hovno;
    		printf("Chcete vediet konkretnu mocninu(2) alebo tabulku od x po 100?(t) ");
    		hovno = getchar();
    			if(hovno == 't'){
    				printf("\nsi pako\n");
    				return 0;
    			}
    			else if(hovno == '5'){
    				float mocnitel, vysledok;
    				printf("Zadaj mocnitel: ");
    				scanf("%g", &mocnitel);
    				vysledok = mocnitel * mocnitel;
    				printf("Vysledok je %g\n", vysledok);
    				return 0;
    			}[/COLOR]
    	return 0;
    	}
    	else {
    		printf("Zadaj jeden zo znakov ktore su napisane vo vete!!\n");
    		
    	
    	}
    
    
    }
    I'm writing this C calc and I wanted to do something like this: You get a possibility to select + or - or * or 2(power of 2). And then I started to write code that when you press 2, then you have posibillity to again select something. But this I cannot do(program doesn't give me any possibility and it just continue to printf). I've been looking over Internet but I cannot find anything about my problem. Red marked code is probably the problem
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Duplicate of [thread=4304]C calc problem[/thread]. Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page