0

I've try this case but I got stuck in a trouble. I just want to to determine length of a string from user input or from console. But it doesn't work.

#include <iostream>
#include <string>
using namespace std;

int main(){
int N;
string S;
char vocal;
vocal = {'a'||'i'||'u'||'e'||'o'};

cout << "Length of Spaghetti Name: ";
cin >> N;
fflush(stdin);

cout << "Spaghetti Name: ";
cin >> S;

if (S[0] != vocal){
    S.erase(0,1);
} else if (S[N] != vocal){
    S.erase(N,1);
}

cout << S << endl;
cin.get();
return 0;
}

expected input

9 Carbonara expected output

arbonara

This program will delete non vocal character in spaghetti names.

halfer
  • 19,824
  • 17
  • 99
  • 186
Aditya
  • 1
  • 1
  • Please post the actual code, not a picture of it! Also [`fflush(stdin)`](https://stackoverflow.com/q/18170410/1270789) is never a good move! – Ken Y-N Dec 21 '18 at 04:25
  • Oh sorry I'll post the code – Aditya Dec 21 '18 at 04:26
  • You don't have a string - `char S;` declares a single character. If you did `std::string S;`, then the length would be `S.length();`. You also most likely don't need to input a length `N` manually. – Ken Y-N Dec 21 '18 at 04:30
  • In this case. The lenght of string set by user in running – Aditya Dec 21 '18 at 04:36
  • @Aditya: Add your expected output and actual output for a test case. – P.W Dec 21 '18 at 05:21
  • expected input 9 Carbonara expected output arbonara – Aditya Dec 21 '18 at 05:42
  • Why do you need the user to enter string length? – r3mus n0x Dec 21 '18 at 05:59
  • Please specify what **exactly** is your current problem. "it doesn't work" is not specific enough for someone to help you. – r3mus n0x Dec 21 '18 at 06:01
  • Also, you're code is attempting to erase **only first and last** non-vowel letters. Is that the intended result or do you actually need to erase all of them in the word? – r3mus n0x Dec 21 '18 at 06:06
  • the case aks user to enter string length – Aditya Dec 21 '18 at 07:40
  • Pretty sure `vocal = {'a'||'i'||'u'||'e'||'o'};` is not what you want - you're logically or'ing the letters together. `vocal` will end up have a value of 1. – Nathan Ernst Dec 22 '18 at 00:03

0 Answers0