The purpose of the program is to first enter a value, then enter another value and at the end the program will display the second value as a percentage of the first value. So basically a percentage calculator.
Here is the code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
// Enter original value and define this variable as "original"
int original;
cout <<"Please enter original value:";
cin >> original;
// Enter value of change
int change;
cout <<"Please enter change:";
cin >> change;
// Calculate change fraction
int fraction;
fraction = change / original;
// Define constant
int constant;
constant = 100;
// Calculate percentage
int percentage;
percentage = fraction * constant;
// Display percentage change
cout <<"Percentage change is:";
cout << percentage <<
cout <<"%";
cout << endl;
// Wait for user
system ("PAUSE");
return 0;
}
Do I need to use a different type of variable? Because the output is "00x4433c4%".
Thank you

New Topic/Question
Reply


MultiQuote




|