-
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;
}
-
Please provide your real code. Aside from syntax errors, this code does not produce the problem you are specifying.
-
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;
}
-
This one runs fine, as well. No problems.
-
Weird. When I hit 'Run', I can only enter one value, it just skips past the rest...
-
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 .....
-
Spot on. I should have seen that.
-
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
-
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 ( << )
-