Like Tree1Likes
  • 1 Post By grumpy

Problem with compiling this reallly basic code

This is a discussion on Problem with compiling this reallly basic code within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #include <fstream> #include <cmath> using namespace std; int main() { double num1; double num2; double num3; int ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    Problem with compiling this reallly basic code

    Code:
    #include <iostream>
    #include <fstream>
    #include <cmath>
    using namespace std;
    
    int main()
    {
        double num1;
        double num2;
        double num3;
        int sum[3] = {num1,num2,num3,};
        int suma = 0;
    
        cout << "Please enter your three numbers\n" << endl;
        cin >> num1 >> num2 >> num3 >> endl;
    
        for ( int x = 0; x < 4; x++ ) {
            suma += sum[x];
            cout << suma << endl;
        }
        cin.get();
    }

    What i want to do is, let the user enter 3 numbers to find the sum of them.

    it says error: no matchfor 'operator>>' in '((std::basic_istream<char, std::char_traits<char>... (line15, (the cin >> num1 >> num2 >> num3... line)

    what does this mean? and how come my code doesn't work? thanks!

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by iluvanimestyle View Post
    Code:
        cout << "Please enter your three numbers\n" << endl;
        cin >> num1 >> num2 >> num3 >> endl;
    why are you trying to input into std::endl? Additionally, there is no reason to use an array here, a std::vector would be more appropriate.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,433
    Quote Originally Posted by iluvanimestyle View Post
    Code:
        double num1;
        double num2;
        double num3;
        int sum[3] = {num1,num2,num3,};
    You are also completely misinterpreting what this does. It does not make sum[0] an alias for num1. When your code later reads num1, the value of sum[0] will NOT change.
    AndrewHunter likes this.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,772
    I am going propose a possible solution to your code:
    Code:
        int sum[3];
        int suma = 0;
    
        cout << "Please enter your three numbers\n" << endl;
        cin >> sum[0] >> sum[1] >> sum[2];
    Also, this is wrong:
    >>for ( int x = 0; x < 4; x++ )
    There are not 4 elements, there are 3 elements, so valid range is 0...2, not 0...3 which your loop iterates over.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with compiling C code in VC++6
    By ghaasemi in forum C++ Programming
    Replies: 2
    Last Post: 05-31-2009, 04:22 AM
  2. Basic compiling problem for a beginner
    By crazychile in forum C Programming
    Replies: 4
    Last Post: 09-21-2008, 02:27 AM
  3. problem compiling code
    By pandaweg in forum C Programming
    Replies: 3
    Last Post: 06-21-2007, 01:04 AM
  4. Problem compiling GMP code
    By Bruno Couto in forum C Programming
    Replies: 2
    Last Post: 10-08-2005, 04:37 PM
  5. problem compiling code and EOF
    By maxthecat in forum C Programming
    Replies: 4
    Last Post: 03-12-2002, 04:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21