Yeronox's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
61 (0.14 per day)
Joined:
12-March 12
Profile Views:
977
Last Active:
User is offline Apr 10 2013 12:52 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   Yeronox is learning C++!

Posts I've Made

  1. In Topic: ** and && stand for?

    Posted 19 Jun 2012

    OK, thank you very much ;)
  2. In Topic: Error with input

    Posted 17 Jun 2012

    When I reverse an array, do I reverse the real array or just a copy?
    Because I think I did something wrong, because if I put "cout" in the reverse function, I won't need the display function, and so what does it stand there for?
  3. In Topic: (C++) Infinite loop if input is alphabetic

    Posted 13 Jun 2012

    View Postbaavgai, on 13 June 2012 - 01:43 PM, said:

    The question is, what exactly do you think (cin >> inc) is returning?

    By way of answer, here's a quick test program:
    #include <iostream>
    
    int main() {
    	using namespace std;
    	double inc;
    	cout << "cin = " << cin << endl;
    	while(true) {
    		istream &result = (cin >> inc);
    		cout << "inc = " << inc << endl;
    		cout << "result = " << result << endl;
    		if (result==0) { break; }
    	}
    	return 0;
    }
    
    


    The answer is... in the code. Hope this helps.

    Yea, that was the real question xD
    So cin returns only true if it's double (if it was char inc, was it only for char?) otherwise it returns a false (and so 0) value, is it correct?
  4. In Topic: (C++) Infinite loop if input is alphabetic

    Posted 13 Jun 2012

    With just
    while (cin >> inc)
    
    

    It works, but can you explain why?
    I thought that I needed >0 for non-negative numbers...
    and what about
    if (isalpha(inc)) break;
    
  5. In Topic: Problem with dynamic array of structures using "new"

    Posted 10 Jun 2012

    View Postishkabible, on 09 June 2012 - 09:35 PM, said:

    tlhIn`toq: in C++ structs have default public visibility.

    the issue is that cin.getline expects a c string. you want just plain getline

    change
    cin.getline(cars[x].make, k);
    

    to
    getline(cin, cars[x].make);
    


    it handles string length to so don't worry about that

    OK, thank you! I didn't know about getline(cin,);
    This code works:
    #include <iostream>
    #include <string>
    const int k = 50;
    using namespace std;
    struct car
    {
        string make;
        int year;
    };
    int main()
    {
        cout << "Enter how many cars to catalog: ";
        int numb;
        cin >> numb;
        cin.get();
        car* cars;
        cars = new car[numb];
        int x, y = 0;
        //car cars[numb];
        for (x=0; x<numb; x++)
            {
                cout << "Enter the make of the " << x+1 << "^ car: ";
                getline(cin, cars[x].make);
                cout << endl;
                cout << "Enter the year it was built: " ;
                cin >> cars[x].year;
                cin.get();
                cout << endl;
            }
            cout << "Here`s your collection:\n";
        for (int i = 0; i < numb; i++)
            {
                cout << cars[i].year << ", " << cars[i].make << endl;
            }
            cout << endl;
        //delete [] car;
        return 0;
    }
    
    

    (Posting it so if someone has the same problem, he can have a look there)

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Programming Languages:
C++

Contact Information

E-mail:
Private

Friends

Comments

Yeronox has no profile comments yet. Why not say hello?