Total Beginner

This is a discussion on Total Beginner within the C++ Programming forums, part of the General Programming Boards category; Hello, this is my second ever attempt at writing a program. It is essentially a model of an economics paper ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    6

    Total Beginner

    Hello, this is my second ever attempt at writing a program. It is essentially a model of an economics paper I wrote. However, when I run it, after I enter the tax value it skips all the other inputs and then delivers an output.

    What I am missing?

    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    
    {
        // Enter the tax
        int tax;
        cout << "Enter the tax rate [0,1]: "
        cin >> tax;
    
        // Enter the gdp (millions)
        int gdp;
        cout << "Enter the gdp level (millions): "
        cin >> gdp;
    
        // Enter the population (millions)
        int pop;
        cout << "Enter the population (millions: ";
        cin >> pop;
    
        // Enter the inflation rate
        int inflation;
        cout << "Enter the inflation rate: ";
        cin >> inflation;
    
        // Enter the openness
        int open;
        cout << "Enter the openness rate [0,1]: ";
        cin >> open;
    
        int intercept;
        intercept = 1.079;
    
    
        // Calculate FDI
        int fdi;
        fdi = intercept + tax * 2.24 + gdp * 1.786 + pop * 0.002 + inflation * -0.048 + open * 0.029;
    
        // Output the results (followed by NewLine)
        cout << "Fdi is: ";
        cout << fdi << endl;
    
        // wait until user is ready before terminating program
        // to allow the user to see the program results
        system("PAUSE");
        return 0;
    }

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    Please provide your real code. Aside from syntax errors, this code does not produce the problem you are specifying.
    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.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    This is a ctrl+a and copy & paste of the entire code. Unless there is another window I am missing?

    Code:
    //
    //  FDI Calculator
    //
    //
    //
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    
    {
        // Enter the tax
        int tax;
        cout << "Enter the tax rate [0,1]: ";
        cin >> tax;
    
        // Enter the gdp (millions)
        int gdp;
        cout << "Enter the gdp level (millions): ";
        cin >> gdp;
    
        // Enter the population (millions)
        int pop;
        cout << "Enter the population (millions: ";
        cin >> pop;
    
        // Enter the inflation rate
        int inflation;
        cout << "Enter the inflation rate: ";
        cin >> inflation;
    
        // Enter the openness
        int open;
        cout << "Enter the openness rate [0,1]: ";
        cin >> open;
    
        int intercept;
        intercept = 1.079;
    
    
        // Calculate FDI
        int fdi;
        fdi = intercept + tax * 2.24 + gdp * 1.786 + pop * 0.002 + inflation * -0.048 + open * 0.029;
    
        // Output the results (followed by NewLine)
        cout << "Fdi is: ";
        cout << fdi << endl;
    
        // wait until user is ready before terminating program
        // to allow the user to see the program results
        system("PAUSE");
        return 0;
    }

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    This one runs fine, as well. No problems.
    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.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Weird. When I hit 'Run', I can only enter one value, it just skips past the rest...

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,287
    You're reading tax rate as an integer, but prompting for a value between 0 and 1.

    I assume you're entering a value between zero and 1, such as .95

    Entering .95 will mean the decimal point is encountered first, the first read will complete, and the decimal point will be left in the stream until the next read. Since all the other input values are also being read as integers .....
    Right 98% of the time, and don't care about the other 3%.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Spot on. I should have seen that.

  8. #8
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    Hi, I have a new problem with the same program so I thought I would keep it in here. So far I have:

    Code:
    //
    //  FDI Calculator
    //
    //
    //
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>
    #include <math.h>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    
    {
        double     intercept;
        double     gdp;
        int        pop;
        double     inf;
        int        fdi;
        double     tax;
        double     open;
        int        country;
    
        cout << "Welcome to the FDI Calculator ";
        system("PAUSE");
    
        // Choice of country
    
        cout << "Enter your choice of country, ie. 8 = 'Ireland': ";
        cin  >> country;
    
        switch (country)
        {
            case 8:
                fdi =       11979;
                tax =       0.125;
                gdp =       201.93;
                pop =       4;
                inf =       118.38;
                open =      151.44;
                break;
    
            default:
                fdi =       0;
                tax =       0;
                gdp =       0;
                pop =       0;
                inf =       0;
                open =      0;
        }
    
        // Calculate current expected FDI
    
        cout << "Current expected FDI for this country is: ";
        fdi << endl;
    
    
        // Enter the tax
        double newtax;
        cout << "Enter your proposed tax rate [0,1]: ";
        cin >> newtax;
    
    
        intercept = 1.079;
    
    
        // Calculate FDI
        double logfdi;
        logfdi = intercept + log(newtax) * -2.24 + log(gdp) * 1.786 + log(pop) * 0.002 + log(inf) * -0.048 + log(open) * 0.029;
    
        // Output the results (followed by NewLine)
        cout << "% Change in Fdi is: ";
        cout << logfdi << endl;
    
        system("PAUSE");
    
        int oldfdi;
        cout << "Enter current FDI [bea]: ";
        cin >> oldfdi;
    
        double newfdi;
        newfdi = oldfdi*(1+(logfdi/100));
    
        cout << "FDI levels are now: ";
        cout << newfdi << endl;
    
        // wait until user is ready before terminating program
        // to allow the user to see the program results
        system("PAUSE");
        return 0;
    }
    When I attempt to build this I get:


    C:\Beginning_Programming-CPP\FDI_Elasticity\main.cpp||In function 'int main(int, char**)':|
    C:\Beginning_Programming-CPP\FDI_Elasticity\main.cpp|56|error: invalid operands of types 'int' and '<unresolved overloaded function type>' to binary 'operator<<'|
    ||=== Build finished: 1 errors, 0 warnings ===|


    What am I doing wrong here?

    Thanks

  9. #9
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    I assume this is it:
    Code:
    cout << "Current expected FDI for this country is: ";
    fdi << endl;
    You are attempting to use fdi as if it were a stream. You need to replace the ; on the line immediately above it with the extraction operator ( << )

  10. #10
    Registered User
    Join Date
    Nov 2010
    Posts
    6
    That's it, thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Restaurant Point-of-Sale Application: Help?!
    By matt.s in forum C Programming
    Replies: 14
    Last Post: 04-16-2010, 05:36 PM
  2. "Poker" AI Results
    By Sang-drax in forum Contests Board
    Replies: 15
    Last Post: 04-10-2010, 04:40 PM
  3. Help with day of the week program
    By Punkakitty in forum C++ Programming
    Replies: 10
    Last Post: 01-14-2009, 05:55 PM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. Replies: 4
    Last Post: 04-22-2003, 12:52 PM

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