Your browser does not seem to support CSS. If images appear below, please disregard them.
It appears that you're running an Ad-Blocker. This site is monetized by Advertising and by ">User Donations; we ask that if you find this site helpful that you whitelist us in your Ad-Blocker, or make a ">Donation to help aid in operating costs.
Previous Thread
Next Thread
Print Thread
Rate This Thread
#17450 - 09/18/04 08:31 AM hmm my output is all funky... c++ help  
Joined: Apr 2002
Posts: 212
Rapture Offline
Rapture  Offline

Joined: Apr 2002
Posts: 212
Just trying to store movie title, year, rating.

here's my code...

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

class Movie
    	Movie(char title, int year, int rating);	
	void print();
      char m_title;
    	int m_year;
    	int m_rating;

Movie::Movie(char title, int year, int rating)
    m_year = year;
    m_rating = rating;
    m_title = title;

    cout << "Year: " << m_year << "," << m_title << ", rating = " << m_rating << endl;

    Movie *data[100];	// array to hold the dynamically created Pair objects
    int num_movies = 0;	// the number of pair objects we have created
    char *title;
    int year, rating;		// hold values read from cin

    // as long as there is an integer to read, read it (as long as not EOF)
    while (cin >> title) 
	//read 2nd integer in pair (dangerous assumption, what if no more nums?)
        cin >> year; 
        cin >> rating;

	// instantiate a new Pair object using the new operator
	data[num_movies] = new Movie(*title, year, rating);

	// we have read another pair of integers, update our counter

    // print out all the pairs pointed to by the data array
    for (int i = 0; i < num_movies; i++)
    	cout << i << endl;

after i compile and run i'm getting crazy output like this:

year: -3242342 , rating = -12342354

won't dispaly the title at all and give me crazy output like that. Any ideas on what I'm doing wrong here?


Sponsored Links
#17451 - 09/29/04 12:27 AM Re: hmm my output is all funky... c++ help  
Joined: Mar 2002
Posts: 93
zenon Offline
Junior Member
zenon  Offline
Junior Member

Joined: Mar 2002
Posts: 93
First of all, your class has a litle mistake.

the char title;
shoulde be char *title;
this because you know hold a single char.

So, I supose that this maybe [censored] it.
Try it out, also do some controlls by adding some few lines like;

cout << title << endl;

just before reading data with

cin >> year;

try that.

- "It's not my code that's useless
it's you loosers being unable to
apprecitate it because of your
lack of skills!"
/zenon - C++ master Apprentice

Member Spotlight
SC, usa
Posts: 506
Joined: March 2002
Show All Member Profiles 
Forum Statistics
Average Daily Posts3
Most Online1,567
Apr 25th, 2010
Latest Postings
There is not any party like an arm party
by bagful on 04/27/17 06:26 AM
The innovative concept keep
by bagful on 04/27/17 06:25 AM
The Nike Blazer Studio Mid Decon
by bagful on 04/27/17 06:24 AM
a fresh white enhance midsole device
by bagful on 04/27/17 06:23 AM
shopping for jewelry with something above
by mikejoey on 04/12/17 08:01 AM
PANDORA North The usa
by mikejoey on 04/12/17 07:38 AM
Pandora’s birthstone products will always
by mikejoey on 04/12/17 07:14 AM
the newest Pandora necklaces crafting facility
by mikejoey on 04/12/17 06:53 AM
an Air Jordan 4 by Off White is in
by mikejoey on 04/12/17 06:35 AM
belonging to the adidas NMD XR1
by mikejoey on 04/12/17 05:50 AM
Top Posters(All Time)
UGN Security 41,138
Gremelin 7,198
§intå× 3,255
SilentRage 1,273
Ice 1,146
pergesu 1,136
Infinite 1,041
jonconley 955
Girlie 908
unreal 860
Top Liked Users (All Time)
§intå× Likes: 3
Black Beard Likes: 1
Cold Sunn Likes: 1
Crime Likes: 1
Cyrez Likes: 1
fleshwound Likes: 1
Ghost Likes: 2
Gremelin Likes: 12
Ice Likes: 1
ninjaneo Likes: 1
Top Liked Users (30 Days)
No Data Found
Powered by UBB.threads™ PHP Forum Software 7.6.0
(Snapshot build 20170206)