New user to C++ on a Mac using xcode. Trying to use IDE correctly

Posted on 2012-09-07
Last Modified: 2016-02-10
First, I'm very new to programming and C++ so if I made a huge flaw in the code below, forgive's possible I screwed up bigtime. I am trying to make a very, very basic program just so I can get started using xcode on my Mac instead of codeblocks on my pc to compile C++ programs

#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
    int a,b,c,d,e,f,g;
    cout << "Enter 6 numbers: ";
    cin >> a >> b >> c >> d >> e >> f >> g;
    cout << a << b;
    return 0;

Open in new window

The above code outputs:
Enter 6 numbers: 

Open in new window

when I type in the 6 numbers ( as '1 2 3 4 5 6')and hit enter, the rest of the program does not run(the   cout << a << b;). I tried running the program from bash also but that too was not working. I'm feeling really dumb right now. Can someone tell me what I'm doing wrong?
Question by:Mark_Co
    LVL 14

    Accepted Solution

    When the program prints "Enter 6 numbers: " you should enter 7 numbers since you have defined 7 int variables (a,b,c,d,e,f,g) in your code and the program expects to get 7 subsequent numbers from input not 6. so type e.g. '1 2 3 4 5 6 7' and you will get the output as:
    '12' (one and two numbers without space if you need space between the two numbers you should change "cout << a << b;" line to "cout << a  << " "<< b;"

    Author Comment

    Crap. I knew I was tired and made a stupid mistake. Sorry, and thank you

    Author Closing Comment

    i apologize for this stupid question. I went back to xcode and got it fixed right away. Going to bed now, hahaha

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now