Requires double input to continue

Hello, can anyone tell me why I need to enter y twice in order for this program to continue ?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
void printInfo () ;
void printMenu () ;
int validInput () ;
int returnString (char *string) ;
int menuChoice () ;
void clearScreen ();
char restartDo ();
void pigLatin ( char userString [] , int max ) ;
void constantsVowels ( char userStr [] , int maxLetter ) ;
int main ()
{
    int userChoice , number;
    char userWord [ 21 ] , decision , enterWord ;
    printInfo () ;
    do{
    
    returnString(userWord);
    
    printMenu () ;
    
    userChoice = menuChoice ();
    
    if(userChoice == 1)
      pigLatin( userWord, number );
    
    else if(userChoice == 2)
        constantsVowels ( userWord , number);
    
    else if(userChoice == 3)
        return 0;
    decision = restartDo ();
    } 
    while(decision == 'y' || decision == 'Y');
    
}




void printInfo () 
{
     printf ( "Welcome To The String Manipulator\n" ) ;
     printf ( "This Program Will Take Any Word You Enter And Either\n" ) ;
     printf ( "~ Convert It To Pig Latin\n" ) ;
     printf ( "~ Count Vowels And Consonants\n" ) ;
     printf ( "_________________________________\n" ) ;
     printf ( "Please Enter A Word (No Spaces, Max Of 20 Characters)\n" ) ;

}

void printMenu() 
{
     printf ( "              [ Options ]\n" ) ;
     printf ( "1) Pig - Latin\n" ) ;
     printf ( "2) Count Vowels and Consonants\n" ) ;
     printf ( "3) Exit\n" ) ;
     printf ( "________________________________________\n" ) ;
     printf ( "Please Enter Your Choice < 1 - 3 >\n" ) ;
}

int returnString(char *string)
{
     scanf("%s", &*string);
     getchar();
     
     
}
int validInput (  ) 
{
    
}

int menuChoice ()
{
    int menu;
    scanf ( "%i" , &menu ) ;
    getchar () ;
    return menu;
    
}
void pigLatin ( char userString [] , int max ) 
{
          char beggining , end ;
     int count ;
     max = max - 1 ;
     userString [ max+1 ] = userString [ 0 ] ;
     for ( count = 1 ; count <= max + 1 ; count ++ )
        {
           printf ( "%c%" , userString [ count ] ) ;
        }
        printf ( "ay" ) ;
     printf ( "\n" ) ;
}

void constantsVowels ( char userStr [0] , int maxLetter ) 
{
          int count , count2 , count3 , vCount = 0 , cCount ;
     int vowel ;
char vowelAllowed [ 13 ] = { 'a' , 'A' , 'e' , 'E' , 'i' , 'I' , 'o' , 'O' , 'u' , 'U' , 'y' , 'Y' } ;

char constantAllowed [ 41 ] = { 'b' , 'B' , 'c' , 'C' , 'd' , 'D' , 'f' , 'F' , 'g' , 'G' , 'h' , 'H' , 'j' , 'J' , 'k' , 'K' , 'l' , 'L' , 'm' , 'M' , 'n' , 'N' , 'p' , 'P' , 'q' , 'Q' , 'r' , 'R' , 's' , 'S' , 't' , 'T' , 'v' , 'V' , 'w' , 'W' , 'x' , 'X' , 'z' , 'Z' } ;
     
     for ( count = 0 ; count < maxLetter ; count ++ )
        {
           for ( count2 = 0 ; count2 < 12 ; count2 ++ )
              {
                 if ( userStr [ count ] == vowelAllowed [ count2 ] )
                   vCount ++ ;
              }
           
           
           for ( count3 = 0 ; count3 < 42 ; count3 ++ )
              {
                 if ( userStr [ count ] == constantAllowed [ count3 ] )
                   {
                      cCount ++ ;
                   }
              }
        }
        
    printf ( "Your Word Has:\n" ) ;
    printf ( "%i" , vCount ) ; printf ( " Vowels\n" ) ; 
    printf ( "%i" , cCount ) ; printf ( " Consonants\n" ) ; 
}

void clearScreen ()
{
     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}

char restartDo ()
{
     char yesNo;
     printf("Would You Like To Manipulate Another Word ?\n");
     scanf("%c", &yesNo);
     getchar(); 
     return yesNo;
}
Don't be mad at me but i had some extra free time to make you similar but different version of your program so i hope you'll like it. Here is the code below:
P.S. Just copy the code so you can have a closer look on it it works properly cos i had time to also test it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
using namespace std;

void printInfo ();
void printMenu();
void pigLatin (string x);
void constantsVowels (string x);


int main()
{
	string word,check;
	do{
                system("CLS");
		printInfo();
		getline(cin,word);
		printMenu();
		getline(cin,check);
		if(check=="1")
		{
			pigLatin (word);
		}
		if(check=="2")
		{
			constantsVowels (word);
		}
		if(check=="3")
		{
			system("CLS");
			cout<<"Thank you for using my program! \n";
			break;
		}
		cout<<"Would You Like To Manipulate Another Word ? (Y/N)\n";
		getline(cin,check);
	}while((check=="Y")||(check=="y"));

	return 0;
}

void printInfo () 
{
     cout<<"Welcome To The String Manipulator\n";
     cout<<"This Program Will Take Any Word You Enter And Either\n";
     cout<<"~ Convert It To Pig Latin\n";
     cout<<"~ Count Vowels And Consonants\n";
     cout<<"_________________________________\n";
     cout<<"Please Enter A Word (No Spaces, Max Of 20 Characters)\n";
}

void printMenu() 
{
     cout<<"              [ Options ]\n";
     cout<<"1) Pig - Latin\n";
     cout<<"2) Count Vowels and Consonants\n";
     cout<<"3) Exit\n";
     cout<<"________________________________________\n";
     cout<<"Please Enter Your Choice < 1 - 3 >\n";
}

void pigLatin (string x)
{
	string::iterator it;
	it=x.begin();
	it++;
	for(;it!=x.end();it++)
	{
		cout<<*it;
	}
	it=x.begin();
	cout<<*it<<"ay"<<endl;
	cout<<endl;
}

void constantsVowels (string x)
{
	int vCount=0;	
	string vowel="aAeEiIoOuUyY";
	string::iterator it,it1;
	for(it=x.begin();it!=x.end();it++)
	{
		for(it1=vowel.begin();it1!=vowel.end();it1++)
		{
			if(*it==*it1)
			{
				vCount++;
				break;
			}
		}
	}
	cout<<"Your word has : \n";
	cout<<vCount<<" Vowels \n";
	cout<<x.size()-vCount<<" Consonants\n ";
}

Hope you like it.
Last edited on
Thank you for doing that, but did you ever find out why it needs 'y' entered twice?
Well i wasn't able to execute your code cos it was giving errors so i can't say what was it!
You don't. The second 'y' should be your new word but there's no menu thing to say that. But regardless...

What is number? The program doesn't work unless I change that to something else.
Last edited on
Number was from a different version of the program I wrote, which shouldnt actualy be in this one, sorry about that.
But, thank you for that simple correction! Can't believe I didn't see that ....
Topic archived. No new replies allowed.