Hi everyone, I need some urgent help and wondered if anyone would know what I'm doing wrong here. I've got a project to do where I need to make a basic bot, basically I want the program to (if the user chooses this option) ask the user a series of questions and for the program to save the answers in a file. I've worked out how to do this but can't seem to incorperate it into my program, the problem is it wont save the text. I don't know if it'd be easier to do it in a different way, I'm a real beginner so if you could demonstrate answers it'd be much appreciated. It's the switch 3 that needs to start asking questions. Here's the code.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int test_value; /*declaring the test_value*/
char username[20]; /*declaring the username variable*/
int mainmenu; /*declaring the mainmenu variable*/
int secmenu; /*declaring the second menu variable*/
char ansone[30];
printf("Welcome to Reading Cinema! Please Enter Your Name: "); /*first printed text, requesting users name*/
scanf ("%s", &username); /* reads users name*/
test_value=(strcmp (username, "Tom")); /*test value is Tom*/
if ( test_value == 0 ) /*if user name matches test value then*/
printf("Hello %s! Great to see you again!\n", username);
else /*if it does not match then*/
printf("Hello %s!\n",username);
printf(" \nPlease Select From The Following Options: \n 1. Cinema Ticket Prices \n 2. Films on Show \n 3. Film Questionnaire \n");
scanf("%d", &mainmenu); /*detects which choice*/
switch(mainmenu) /*first switch statement*/
{
case 1:{ printf("\nYou Chose Ticket Prices.\nPlease choose from the following:\n1.Adult\n2.Child\n3.Student\n"); break;}
case 2:{ printf("\nYou Chose Films on Show.\nPlease choose from the following films to see times:\n4.Watchmen\n5.The Boat That Rocked\n6.Slumdog Millionaire\n7.Paul Blart: Mall Cop\n8.New In Town\n"); break;}
case 3:{ printf("\nThankyou For Agreeing To Take Part In Our Quick Questionnaire!\n");
{
FILE *file_ptr;
file_ptr = fopen("answerone.txt", "w");
printf( "What Is Your Favourite Ever Film?\n" );
gets(ansone);
fputs(ansone, file_ptr);
fclose(file_ptr);
}
break;}
}
scanf("%d", &secmenu);
switch (secmenu)
{
case 1:{ printf("\nAdult Ticket Price:\n7 pounds\n"); break;}
case 2:{ printf("\nChild Ticket Price:\n5 pounds\n"); break;}
case 3:{ printf("\nStudent Ticket Price:\n6 pounds\n"); break;}
case 4:{ printf("\nWatchmen\n8.00\n9.00\n12.00\n14.00\n16.00\n20.00\n21.00\n22.00\n"); break;}
case 5:{ printf("\nThe Boat That Rocked\n11.00\n12.00\n13.00\n13.30\n16.00\n21.40\n22.00\n23.00\n"); break;}
case 6:{ printf("\nSlumdog Millionaire\n14.00\n16.00\n20.00\n21.00\n22.00\n"); break;}
case 7:{ printf("\nPaul Blart: Mall Cop\n14.00\n16.00\n20.00\n22.30\n23.00\n"); break;}
case 8:{ printf("\nNew In Town\n11.00\n12.00\n13.00\n16.30\n18.00\n"); break;}
}
return 0;
}
Thanks!