i am trying to send a string that is "genrecode" back to my main function from the my other function known as char Vote. At first, i used the 'int' data type for the variable "genreCode" since its just integers but i wanted to see if i can send it as a string. How do i do that?
#include <stdio.h>
#include<string.h>
void View_Genre();
char Vote();
void View_Result(int, int, int);
void Exit(int, int , int);
int main ()
{
int option;
char genreCode[2];
int rock=1;
int pop=1;
int country=1;
int Trock=0;
int Tcountry=0;
int Tpop=0;
printf("WELCOME TO MUSIC GENRE VOTING SYSTEM\n");
printf("View Genre\n");
printf("Vote\n");
printf("View Result\n");
printf("Exit\n");
do
{
printf("\nInput option : ");
scanf("%d", &option);
switch(option)
{
case 1 : View_Genre();
break;
case 2 : genreCode=Vote();
if(strcmp(genreCode,"11")==0)
{
Trock=Trock+rock;
}
else if(strcmp(genreCode,"22")==0)
{
Tpop=Tpop+pop;
}
else if(strcmp(genreCode,"33")==0)
{
Tcountry=Tcountry+Tpop;
}
break;
case 3 : View_Result(Trock, Tpop, Tcountry);
break;
case 4 :Exit(Trock, Tpop, Tcountry);
}
}while(option==1 || option==2 || option==3);
printf("\nThank you.");
return 0;
}
void View_Genre()
{
printf("GENRE CODE\n");
printf("ROCK 11 \n");
printf("Pop 22 \n");
printf("Country 33 \n\n");
}
char Vote()
{
char genreCode[2];
printf("Enter genre code : ");
scanf("%d", &genreCode);
if(strcmp(genreCode,"11")==0)
{
printf("Your favourite genre is Rock");
}
else if(strcmp(genreCode,"22")==0)
{
printf("Your favourite genre is Pop");
}
else if(strcmp(genreCode,"33")==0)
{
printf("Your favourite genre is Country");
}
return genreCode;
}
void View_Result(int Nrock, int Npop, int Ncountry)
{
printf("GENRE VOTES\n");
printf(" Rock %d \n", Nrock);
printf(" Pop %d \n", Npop);
printf(" Country %d \n", Ncountry);
}
void Exit(int Nrock,int Npop,int Ncountry)
{
char popular[10];
if(Nrock!=0 || Npop!=0 || Ncountry!=0)
{
if(Nrock>Npop)
{
if(Nrock>Ncountry)
{
strcpy(popular,"Rock");
}
else
{
strcpy(popular,"Country");
}
}
else if(Npop>Ncountry)
{
strcpy(popular,"Pop");
}
else
{
strcpy(popular,"Country");
}
printf("The most popular music genre is : %s\n", popular);
}
else
{
printf("\nYou have not vote any genre\n");
}
}
The rest are all correct. I just need to find out how do i send back a string to my main function.