5 Replies - 612 Views - Last Post: 20 January 2009 - 11:41 AM Rate Topic: -----

#1 maria_isabel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 09

There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 09:15 AM

I neeed a program to perform the following tasks:
• Read in a c-string from the user.
• Reverse the string (e.g. “ABC” would become “CBA”).
• Make all of the characters uppercase.
• Remove all the vowels from the string
• Print out the new c-string.
See the screenshot below as a guide:

Please enter a string of at most 30 characters:
The quick brown fox...
Here is your vowel-free string!
...XF NWRB KCQ HT
Press any key to continue . . .


the program i have does not work properly but it compiles and run and i dont know whats wrong with it

Is This A Good Question/Topic? 0
  • +

Replies To: There is a program that does not work properly, but compiles and runs

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 09:16 AM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#3 Drekey  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Re: There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 09:28 AM

Show us the code Maria
Was This Post Helpful? 0
  • +
  • -

#4 maria_isabel  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 20-January 09

Re: There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 11:08 AM

#include <iostream>
#include <cstdlib>

using namespace std;


int main()
{//count will hold the number of characters in the character array
 //number will mark the end of the characters after the vowels are removed
 //myString is the string(character array) that the user enters
 //targetString is storage for the uppercase version
 //noVowel will store the vowel eliminated string 
 int i,count, number;  
 char myString[31], targetString[31], noVowel[31];
 
 cout<<"Please enter a string of at most 30 characters: "<<endl;
 cin.get(myString,31);
 //first need to find the length of the string
  i=2;
 while (myString[i]!='\0')
	 i++;	
 count=i;
 targetString[count]='\0';
 //loop to uppercase and reverse the string
 for (i=count-1;i>=0;i--)
	 targetString[count]=toupper(myString[i]);
 number=0;
 //strip all the vowels out
 for(i=0;i<=count;i++){
	 if(targetString[i]!='A' && targetString[i]!='E' && targetString[i]=='I' 
			&& targetString[i]!='O'&&targetString[i]!='U') {
	   noVowel[number]= targetString[i];												   
	   number++;													
	 }//end if
 }//end for
 //null terminate the string
 noVowel[number]='\0';
 
 cout<<"Here is your vowel-free string!";
 cout<<endl;
 cout<<targetString[i]<<endl;
 system("PAUSE");
 return 0;
}


This post has been edited by maria_isabel: 20 January 2009 - 11:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 Drekey  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Re: There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 11:34 AM

what is it printing?

cause i see you're printing just one element from the targetstring. dunno if that's the problem.
Was This Post Helpful? 0
  • +
  • -

#6 dan_ram  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 141
  • Joined: 15-August 07

Re: There is a program that does not work properly, but compiles and runs

Posted 20 January 2009 - 11:41 AM

i was quite confused but i've made some changes:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
	int i, count, number;
	char myString[31], targetString[31], noVowel[31];
	cout << "Please enter a string of at most 30 characters: " << endl;
	cin.get(myString, 31);
	/* //first need to find the length of the string
	  i=2;
	 while (myString[i]!='\0')
		 i++;
	 count=i;
	 targetString[count]='\0';*/
	count = strlen(myString);
	targetString[count+1]='\0';
	for (i = count;i >= 0;i--,count--)
		targetString[count] = toupper(myString[i]);
	number = 0;
	for (i = 0;i <= strlen(myString);i++)
	{
		if (targetString[i] != 'A' && targetString[i] != 'E' && targetString[i] != 'I'
				&& targetString[i] != 'O' && targetString[i] != 'U')
		{
			noVowel[number] = targetString[i];
			number++;
		}
	}
	noVowel[number] = '\0';
	cout << "Here is your vowel-free string:";
	cout << endl;
	cout << noVowel << endl;
	system("PAUSE");
	return 0;
}



the changes:
you can use strlen to find the length of string,
in the loop to reverse and uppercase, you had not reduced the value of count,
mostly, you gave targetString[i]=='i' :D
while outputting, to get the whole string just say cout<<noVowel and not the with "i"
Was This Post Helpful? 1

Page 1 of 1