RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1438 | Replies: 7
Reply
Join Date: Sep 2004
Posts: 9
Reputation: kind4ever is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kind4ever kind4ever is offline Offline
Newbie Poster

Help help me with this program

  #1  
Oct 10th, 2004
I'm learn c++ alone and need help to write programs
plz help me :cry:


A.Write is the greatest number?
You have to stor. In an array, twenty integer number given by the user. One these numbers are stored in this array, you have to find the greatest number and print it.

Note:
To manipulate the array in this exercise you should use only pointers.


------------------------------------------------------------------------------
B. Copy a string in an array using Pointers.

The user give you two strings (assume maximum for each string is 50 characters) ,you have to copy the shortest string in an array. Once this string is hold in an array, you must print it using pointers.

Hint:
The function strcmp can help you to resolve this exercise. This functions is included in the library cstring.

Function: int strcmp ( const char *s1, const char *s2 );

Description:
Compares the string s1 with the string s2. The function returns a value of zero, less than zero or greater than zero if s1 is equal to , less than or greater than s2, respectively.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,766
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: help me with this program

  #2  
Oct 10th, 2004
It looks like you forgot to read the Announcement. Post the code you have like this.

[code]/* your code here */[/code]
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 12
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: help me with this program

  #3  
Oct 11th, 2004
In case you weren't quick enough to read the Announcement that Dave was kind enough to post, please post some code of your own that you're working on. When you post questions in this manner, it seems that they're homework questions. We're not here to do your homework for you- we're here to help you learn.
Alex Cavnar, aka alc6379
Reply With Quote  
Join Date: Sep 2004
Posts: 9
Reputation: kind4ever is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kind4ever kind4ever is offline Offline
Newbie Poster

Re: help me with this program

  #4  
Oct 11th, 2004
I try to solve it plz help me
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,336
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 12
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: help me with this program

  #5  
Oct 11th, 2004
Originally Posted by kind4ever
I try to solve it plz help me

That's great that you tried. Did you write any code in your attempts? Please post it here, so that we might help you troubleshoot it.
Alex Cavnar, aka alc6379
Reply With Quote  
Join Date: Sep 2004
Posts: 9
Reputation: kind4ever is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kind4ever kind4ever is offline Offline
Newbie Poster

Re: help me with this program

  #6  
Oct 12th, 2004
thank's alot I'll put it here when i finished
Reply With Quote  
Join Date: Sep 2004
Posts: 9
Reputation: kind4ever is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kind4ever kind4ever is offline Offline
Newbie Poster

Re: help me with this program

  #7  
Oct 12th, 2004
I try and I wrote this code

#include <iostream.h>
#include <string.h>
#include <conio.h>

void main()
{
char str1[6], str2[6], shortest[6];
char *ptr;
int  cmp;

clrscr();

cout << "Enter str1 ..." << endl;
cin >> str1;

cout << endl << "Enter str2  ..." << endl;
cin >> str2;

//      ....... comparing strings and cop to array SHORTEST ........

cout << endl << "Shortest: ";
*ptr = shortest;
while (*ptr) cout << *ptr++;

getch();
} 


but I didn't understand the function how i can use it
and I think this function not use for copy??
Reply With Quote  
Join Date: Sep 2004
Posts: 9
Reputation: kind4ever is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
kind4ever kind4ever is offline Offline
Newbie Poster

Re: help me with this program

  #8  
Oct 13th, 2004
look to this

it's not work i compile it but it's not the value of max num

#include <iostream>

using std::cout;
using std::cin;
using std::endl;


int main()
{
	int num[2];
	int *ptr;
	int i , max = 0;

	cout << "Enter the 20 numbers: "<< " "<< endl;

	for (i = 0; i < 2; ++i)
		cin >> num[i];

    ptr = &num[2];

    for (i = 0; i < 2; ++i)
		if(*ptr > max)
		{
			max = *ptr;
		    *(ptr++);
		}

		cout << "MAX = " <<max<< endl;
	
	
	return 0 ;
}
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:03 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC