Need help

This is a discussion on Need help within the C Programming forums, part of the General Programming Boards category; I am suppose to write a program that presents a main menu to a user. The main menu should present ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    Need help

    I am suppose to write a program that presents a main menu to a user. The main menu should present the user with two option. 1) convert a temperature or 2) quit the program. If the user selects the first option, she should be prompted to enter her name, after which the screen should clear, followed by a presentation of a conversion menu the conversion menu must provide six temperature conversions.


    In addition to displaying the conversions to the screen as output it must collect the following data written to a file tmpstat.txt
    total conversions by type for each user
    total conversion for each user
    total conversion by type for all users
    total conversion for all user.


    Here is my source code i wrote up
    i have no clue as to how to collect the data in the paragraph above to write to the file? Can anyone help me with how to collect the data? I know were suppose to use a loop but i don't know where to put it?

    program:
    Code:
    
    #include <stdio.h>
    #include <string.h>
    #define MAX 20
    
    void Greetings(void);
    void getchoice(void);
    void cmenu(void);
    void ftoc(double temp, char name);
    void ctof(double temp, char name);
    void ftoK(double temp, char name);
    void ctoK(double temp, char name);
    void Ktof(double temp, char name);
    void Ktoc(double temp, char name);
    void displayresult(double Ctemp, double temp, char name);
    
    int main(void)
    {
    	Greetings();
        getchoice();
        
    	return (0);
    }
    
    void Greetings(void)
    {   
       printf("Hello, this program displays menu options for temperature conversions\n");
       printf("of Fahrenheit, Celsius, and Kelvin.\n\n\n");
    }
    
    void getchoice(void)
    {
       char ch;
       char *name[MAX];
       
       printf("          Main Menu           \n");
       printf("------------------------------\n");
       printf("a. Temperature Conversion\n");
       printf("q. Quit the program\n");
       printf("Enter the letter of your choice:\n");
       scanf("%c", &ch);
       
       if (ch == 'a') 
       {
    	   printf("Hi, please enter your first name.\n");
           scanf("%s", &name);
    	   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	   cmenu();
       }
       else (ch == 'q');
    	   printf("Goodbye!\n");
       
    }
    
    void cmenu(void)
    {
       int choice;
       double temp;
       char name;
       
           while (choice != 7)
    	   {
           printf("       Conversion Menu        \n");
           printf("------------------------------\n");
           printf("1. Fahrenheit to Celsius\n");
           printf("2. Celsius to Fahrenheit\n");
           printf("3. Fahrenheit to Kelvin\n");
           printf("4. Celsius to Kelvin\n");
           printf("5. Kelvin to Fahrenheit\n");
           printf("6. Kelvin to Celsius\n");
           printf("7. Main Menu\n");
    	   printf("Enter the number of your choice:");
    	   scanf("%d", &choice);
    	   
       
    	   
    	   switch (choice)
    	   {
               case 1 : ftoc(temp, name);
    			        break;
    
               case 2 : ctof(temp, name);
    			        break;
    	
    	       case 3 : ftoK(temp, name);
    			        break;
    
    	       case 4 : ctoK(temp, name);
    			        break;
    
    	       case 5 : Ktof(temp, name);
    			        break;
    
    	       case 6 : Ktoc(temp, name);
    			        break;
    
    	       case 7 : getchoice();
    			        break;
    			        
    	   }  
       }
    
    }
    
    void getdata(double *temp)
    {
    	printf("Please enter your temperature to be converted:\n");
    	scanf("%lf", temp);
    }
    
    void ftoc(double temp, char name)
    {
         
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp * 1.8) + 32;
    	displayresult(Ctemp, temp, &name);
    }
        
    void ctof(double temp, char name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp - 32) / 1.8;
    	displayresult(Ctemp, temp, &name);
    }
    
    void ftoK(double temp, char name)
    {
        double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp * 1.8) + 32) +273.15;
        displayresult(Ctemp, temp, &name);
    }
    void ctoK(double temp, char name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp + 273.15;
        displayresult(Ctemp, temp, &name);
    }
    
    void Ktof(double temp, char name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp - 273.15) * 1.8) + 32;
        displayresult(Ctemp, temp, &name);
    }
    
    void Ktoc(double temp, char name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp - 273.15;
        displayresult(Ctemp, temp, &name);
    }
    
    void displayresult(double Ctemp, double temp, char name)
    {
    	printf("%s's Conversions:\n\n", &name);
        printf("Original temperature was %.1lf and converted temperature is %.1lf.\n\n", temp, Ctemp);
    }

    Here is my source code i wrote up

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    Need help counting data.

    Here is my source code i wrote up
    i have no clue as to how to collect the data in the paragraph above to write to the file? Can anyone help me with how to collect the data? I know were suppose to use a loop but i don't know where to put it?

    I am suppose to write a program that presents a main menu to a user. The main menu should present the user with two option. 1) convert a temperature or 2) quit the program. If the user selects the first option, she should be prompted to enter her name, after which the screen should clear, followed by a presentation of a conversion menu the conversion menu must provide six temperature conversions.

    In addition to displaying the conversions to the screen as output it must collect the following data written to a file tmpstat.txt
    total conversions by type for each user
    total conversion for each user
    total conversion by type for all users
    total conversion for all user.
    Code:
    #include <stdio.h>
    #include <string.h>
    #define MAX 20
    
    void Greetings(void);
    void getchoice(void);
    void cmenu(void);
    void ftoc(double temp, char name);
    void ctof(double temp, char name);
    void ftoK(double temp, char name);
    void ctoK(double temp, char name);
    void Ktof(double temp, char name);
    void Ktoc(double temp, char name);
    void displayresult(double Ctemp, double temp, char name);
    
    int main(void)
    {
    	Greetings();
        getchoice();
        
    	return (0);
    }
    
    void Greetings(void)
    {   
       printf("Hello, this program displays menu options for temperature conversions\n");
       printf("of Fahrenheit, Celsius, and Kelvin.\n\n\n");
    }
    
    void getchoice(void)
    {
       char ch;
       char name[MAX];
       
       printf("          Main Menu           \n");
       printf("------------------------------\n");
       printf("a. Temperature Conversion\n");
       printf("q. Quit the program\n");
       printf("Enter the letter of your choice:\n");
       scanf("%c", &ch);
       
       if (ch == 'a') 
       {
    	   printf("Hi, please enter your first name.\n");
           scanf("%s", name);
    	   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	   cmenu();
       }
       else if(ch == 'q');
    	   printf("Goodbye!\n");
       
    }
    
    void cmenu(char *name)
    {
       int choice;
       double temp;
       
       
           while (choice != 7)
    	   {
           printf("       Conversion Menu        \n");
           printf("------------------------------\n");
           printf("1. Fahrenheit to Celsius\n");
           printf("2. Celsius to Fahrenheit\n");
           printf("3. Fahrenheit to Kelvin\n");
           printf("4. Celsius to Kelvin\n");
           printf("5. Kelvin to Fahrenheit\n");
           printf("6. Kelvin to Celsius\n");
           printf("7. Main Menu\n");
    	   printf("Enter the number of your choice:");
    	   scanf("%d", &choice);
    	   
       
    	   
    	   switch (choice)
    	   {
               case 1 : ftoc(temp, name);
    			        break;
    
               case 2 : ctof(temp, name);
    			        break;
    	
    	       case 3 : ftoK(temp, name);
    			        break;
    
    	       case 4 : ctoK(temp, name);
    			        break;
    
    	       case 5 : Ktof(temp, name);
    			        break;
    
    	       case 6 : Ktoc(temp, name);
    			        break;
    
    	       case 7 : getchoice();
    			        break;
    			        
    	   }  
       }
    
    }
    
    void getdata(double *temp)
    {
    	printf("Please enter your temperature to be converted:\n");
    	scanf("%lf", temp);
    }
    
    void ftoc(double temp, char *name)
    {
         
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp - 32) / 1.8;
    	
    	displayresult(Ctemp, temp, name);
    }
        
    void ctof(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp * 1.8) + 32;
    	displayresult(Ctemp, temp, name);
    }
    
    void ftoK(double temp, char *name)
    {
        double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp * 1.8) + 32) +273.15;
        displayresult(Ctemp, temp, name);
    }
    void ctoK(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp + 273.15;
        displayresult(Ctemp, temp, name);
    }
    
    void Ktof(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp - 273.15) * 1.8) + 32;
        displayresult(Ctemp, temp, name);
    }
    
    void Ktoc(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp - 273.15;
        displayresult(Ctemp, temp, name);
    }
    
    void displayresult(double Ctemp, double temp, char *name)
    {
    	printf("%s's Conversions:\n\n", name);
        printf("Original temperature was %.1lf and converted temperature is %.1lf.\n\n", temp, Ctemp);
    }

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    To Salem

    Sorry about that;

    I had already fixed the code on my computer I just failed to update the code. And i'm not asking for the same thing its just that i didn't think anyone noticed my problem yesterday most likely because my wording was confusing.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    I need help on the data collection question

    There its all fixed

    Code:
    #include <stdio.h>
    #include <string.h>
    #define MAX 20
    
    void Greetings(void);
    void getchoice(void);
    void cmenu(char *name);
    void ftoc(double temp, char *name);
    void ctof(double temp, char *name);
    void ftoK(double temp, char *name);
    void ctoK(double temp, char *name);
    void Ktof(double temp, char *name);
    void Ktoc(double temp, char *name);
    void displayresult(double Ctemp, double temp, char *name);
    
    int main(void)
    {
    	Greetings();
        getchoice();
        
    	return (0);
    }
    
    void Greetings(void)
    {   
       printf("Hello, this program displays menu options for temperature conversions\n");
       printf("of Fahrenheit, Celsius, and Kelvin.\n\n\n");
    }
    
    void getchoice(void)
    {
       char ch;
       char name[MAX];
       
       printf("          Main Menu           \n");
       printf("------------------------------\n");
       printf("a. Temperature Conversion\n");
       printf("q. Quit the program\n");
       printf("Enter the letter of your choice:\n");
       scanf("%c", &ch);
       
       if (ch == 'a') 
       {
    	   printf("Hi, please enter your first name.\n");
           scanf("%s", name);
    	   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
    	   cmenu(name);
       }
       else if(ch == 'q');
    	   printf("Goodbye!\n");
       
    }
    
    void cmenu(char *name)
    {
       int choice;
       double temp;
       
       
           while (choice != 7)
    	   {
           printf("       Conversion Menu        \n");
           printf("------------------------------\n");
           printf("1. Fahrenheit to Celsius\n");
           printf("2. Celsius to Fahrenheit\n");
           printf("3. Fahrenheit to Kelvin\n");
           printf("4. Celsius to Kelvin\n");
           printf("5. Kelvin to Fahrenheit\n");
           printf("6. Kelvin to Celsius\n");
           printf("7. Main Menu\n");
    	   printf("Enter the number of your choice:");
    	   scanf("%d", &choice);
    	   
       
    	   
    	   switch (choice)
    	   {
               case 1 : ftoc(temp, name);
    			        break;
    
               case 2 : ctof(temp, name);
    			        break;
    	
    	       case 3 : ftoK(temp, name);
    			        break;
    
    	       case 4 : ctoK(temp, name);
    			        break;
    
    	       case 5 : Ktof(temp, name);
    			        break;
    
    	       case 6 : Ktoc(temp, name);
    			        break;
    
    	       case 7 : getchoice();
    			        break;
    			        
    	   }  
       }
    
    }
    
    void getdata(double *temp)
    {
    	printf("Please enter your temperature to be converted:\n");
    	scanf("%lf", temp);
    }
    
    void ftoc(double temp, char *name)
    {
         
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp - 32) / 1.8;
    	
    	displayresult(Ctemp, temp, name);
    }
        
    void ctof(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = (temp * 1.8) + 32;
    	displayresult(Ctemp, temp, name);
    }
    
    void ftoK(double temp, char *name)
    {
        double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp * 1.8) + 32) +273.15;
        displayresult(Ctemp, temp, name);
    }
    void ctoK(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp + 273.15;
        displayresult(Ctemp, temp, name);
    }
    
    void Ktof(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = ((temp - 273.15) * 1.8) + 32;
        displayresult(Ctemp, temp, name);
    }
    
    void Ktoc(double temp, char *name)
    {
    	double Ctemp;
    	getdata(&temp);
    	Ctemp = temp - 273.15;
        displayresult(Ctemp, temp, name);
    }
    
    void displayresult(double Ctemp, double temp, char *name)
    {
    	printf("%s's Conversions:\n\n", name);
        printf("Original temperature was %.1lf and converted temperature is %.1lf.\n\n", temp, Ctemp);
    }
    [/B][/QUOTE]
    Last edited by duty11694; 11-16-2002 at 04:07 PM.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    counter problem

    would it be possible if i put the counters in the switch statement that it would be sufficient to collect the data need to put into the file. another question how would i store the counter in the file i know how to save to a file and opening the file but how would i save the counter each time. plus can't use global variables.
    Last edited by duty11694; 11-16-2002 at 06:08 PM.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    >when you do option 7

    What do you mean when you said when you do option 7? Is that where i put the counters. If i put the counters there how would it collect the stats fot he conversions.

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    18

    output

    I s there anyway i can display the output in my program like

    Alice's conversions

    99.9 degrees Fahrenheit = 88.8 kelvins
    99.9 degrees celsius = 88.8 degrees fahrenheit

    instead of having the ouput be displayed everytime conversion ocurrs.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21