Thread: need help!!!!

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49

    need help!!!!

    hi there i want to make a console application which the user can pick whether a calculator or a temp converter but the problem is it wont compile at all need help......

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    
    
    int main(void)
    
    {
    
        int menu, menu1, numb1, numb2, total;
        int valid = 0;
        while(valid == 0){  
        printf("ENTER CHOICE\n");
        puts("1 = calculator");
        puts("2 = TEMP converter");
        scanf("%d", &menu);
        if((menu == 1) || (menu == 2))
        valid = 0;
        
        else{
                printf("****GOODBYE YOU PICK A WRONG CHOICE*****\n");
                    getch();
                    return 0;
                }
                if(menu == 1)
                {
                    printf("ENTER IN FIRST NUMBER\n");
                    scanf("%d", &numb1);
                    puts("enter second number");
                    scanf("%d", &numb2);
                    puts("Enter in choice");
                    puts("1 = addition");
                    puts("2 = subtraction");
                    scanf("%d", &menu);
                    switch(menu){
                        case 1: total = numb1 + numb2; break;
                        case 2: total = numb1 - numb2; break;
                        default: printf("sorry wrong choice\n");
                }    
                    printf("%d\n", total);
                   
                {
                getch();               
                return 0;
            }
        }
        else if(menu ==2)
        {
            puts("enter temp");
            scanf("%d", &numb1);
            puts("enter in choice");
            puts("1 = fahr to celsius");
            puts("2 = celsius to fahr");
            scanf("%d", &menu1);
            switch(menu1){
                case 1: total = (5.0/9.0)*(numb1-32); break;
                case 2: total = (9.0/5.0)*numb1+32; break;
                default: printf("Wrong selection\n");
                }
                
                printf("%d\n", total);
                getch();
                return 0;
        }    
           }    
                                                                                                                
        getch();
        return 0;
      
    }
    that's the code[not yet finish]////// help needed...
    Last edited by limitmaster; 05-25-2006 at 06:08 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    What error message do you get when trying to compile?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Generally if your program won't compile, it tells you why. These are known as "error messages". Also pay attention to "compiler warnings". If you don't have any of either, turn them on in your IDE, or use the appropriate flags for your compiler.

    Here's a tip: No one wants to copy your program to a file, save it, and run it through their compiler, just to get the warnings and errors you neglected to include.

    If you get a huge list of hundreds of errors and warnings, start with the first one. Look at the line number, or those lines around that point, and fix that problem. Once you're done with that one, compile again. Repeat until done.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    >> case 1: total = (5.0/9.0)*(numb1-32); break;
    >> case 1: total = (9.0/5.0)*numb1+32; break;

    See anything wrong there? also, you have a brace mismatch -
    need to add one more brace at the end of the program, which
    would be easier to fix if you had used consistent indentation.
    Stop using just main - its int main for a reason - this is my second
    time telling you this today

    Also, there are better alternatives to system ("pause") -
    check out the first one on this link
    Last edited by Richie T; 05-25-2006 at 04:38 AM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  5. #5
    Registered User
    Join Date
    May 2006
    Location
    in your head
    Posts
    49
    sorry for that(,'') i didn't see it but anyway thanks and for the link thanks also btw i didn't learned system("pause") from K and R i learned it from other tutorials but i forgot the link and also the warnings i haven't noticed that i picked c++ project instead c....thanks......
    Richie T, Quantum1024 and quzah thanks i manage to fix the problem.....
    Last edited by limitmaster; 05-25-2006 at 06:13 AM.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You can restructure your code a bit:

    Code:
    if(1) DO THIS;
    else if(2) DO THAT;
    else PRINT ERROR;
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed