<< code snippet>>
double coeffIdeal[20], coeffLiquid[20], coeffSolid[20];
long coeffIdealSize, coeffLiquidSize, coeffSolidSize;
compPtr->GetData(THP::HIDEALCOEFS, coeffIdeal, coeffIdealSize, 20);
compPtr->GetData(THP::HLSATCOEFS, coeffLiquid, coeffLiquidSize, 20);
compPtr->GetData(THP::HSSATCOEFS, coeffSolid, coeffSolidSize, 20);
strcpy(CompTab, argv[1]);
strcat(CompTab, "_coeffs.csv");
ofstream myfileComp;
myfileComp.open(CompTab);
myfileComp << "Name ," << argv[1] <<", Ideal, Liquid, Solid"<< endl;
myfileComp << "Formula" << endl ;
myfileComp << "MW ," << MW << endl;
myfileComp << "Tc(K) ," << Tc << endl;
myfileComp << "NBP(K) ,"<< NBP << endl;
myfileComp << "NMP(K) ,"<< NMP << endl;
myfileComp << "Correlation Number ," ","<< corrIdeal << "," << corrLiquid << "," << corrSolid << endl;
myfileComp << "Factor" "," ","<< conffIdeal << "," << conffLiquid << "," << conffSolid << endl;
myfileComp << "Coeff" "," << coeffIdeal;
myfileComp.close();
I am trying to print coefficients to excel csv file from visual studio using C++ can someone help me? The coefficients should print in the column in excel.
Related
So, I had my dates stored as a string, and loop through it but it cannot find the matching date from the vector. To make sure it loops through the vector, I put else at the bottom there and for every time it loops through the vector and is not found the date will display it.
[1] https://i.stack.imgur.com/KA17B.png
cout << "Please enter a date: ";
cin >> searchByDate;
for (columnCount = 0; columnCount < currentRow; columnCount++)
{
if (searchByDate == DATE[columnCount])
{
cout << DATE[columnCount] << "\t" << CUSTNAME[columnCount] << "\t" << GENDER[columnCount] << "\t" << IDENTITY[columnCount] << "\t";
cout << TELEPHONE[columnCount] << "\t" << TYPE[columnCount] << "\t" << THERAPIST[columnCount] << "\t" << CHARGES[columnCount] << endl;
totalRevenue += CHARGES[columnCount];
}
else
cout << "date 404";
Help! Emergency!
I am trying to get the program to read 2 string then convert them to ASCII value and compare the 2 value.
I am not sure how to change the string to ASCII value for the comparing function to work.
#include <iostream>
int main()
{
char ch[50];
std::cout << "Enter a character: ";
std::cin.getline(ch, sizeof(ch));
std::cout << "ASCII Value of " << ch << " is " << int(ch) << std::endl;
char cha[50];
std::cout << "Enter a character: ";
std::cin >> cha;
std::cout << "ASCII Value of " << cha << " is " << int(cha) << std::endl;
if (ch[50] == cha[50]) {
std::cout << "ASCII Value of " << cha << " is " << "equal to " << ch;
return 0;
}
else if (ch > cha) {
std::cout << ch << " is greater than " << cha << std::endl;
std::cout << int(ch) - int(cha) << "is the differents between the two " ;
return 1;
}
else
{
std::cout << ch << " is less than " << cha;
}
system("PAUSE");
}
char ch[50];
std::cout << "Enter a character: ";
std::cin.getline(ch, sizeof(ch));
char ch[50] is "array of character" otherwise known as "string"
if (ch[50] == cha[50]) { ... }
Both ch and ch50 have 50 elements. The index starts at zero, that means the last valid element is ch[49]. ch[50] is buffer overflow and causes undefined behavior.
You want instead to declare a single character, char ch; and read that character. Or declare ch[50] and read the string, and do a comparison for ch[0] (that's the first element in the index)
int main()
{
char ch;
char cha;
std::cout << "Enter one character: ";
std::cin >> ch;
std::cout << "ASCII Value of " << ch << " is " << int(ch) << std::endl;
std::cout << "Enter a character: ";
std::cin >> cha;
std::cout << "ASCII Value of " << cha << " is " << int(cha) << std::endl;
if(ch == cha)
{
std::cout << "ASCII Value of " << cha << " is " << "equal to " << ch;
}
else
{
std::cout << ch << " is greater than " << cha << std::endl;
if(ch > cha)
std::cout << ch << " is greater than " << cha << std::endl;
else
std::cout << ch << " is less than " << cha;
}
return 0;
}
How do I get the range of the data set? Also known as the bounding box for the data. The data is read with the StructuredPointsReader.
Because vtkStructuredPoints (the type of GetOutput() on a vtkStructuredPointsReader) is a subclass of vtkDataSet, you can use the GetBounds(double[6]) function of vtkDataSet. Here is an example:
double bounds[6];
structuredPointsReader->Update();
structuredPointsReader->GetOutput()->GetBounds(bounds);
std::cout << "xmin: " << bounds[0] << " "
<< "xmax: " << bounds[1] << std::endl
<< "ymin: " << bounds[2] << " "
<< "ymax: " << bounds[3] << std::endl
<< "zmin: " << bounds[4] << " "
<< "zmax: " << bounds[5] << std::endl;
#include <iostream>
#include <iomanip>
using namespace std;
int main () // print to console: 3.0*5.0=15.00
{
double a;
double b;
a =(3.0);
b =(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << a*b << "\n" << endl;
return 0;
}
int calculate () // print to console: (7.1*8.3)-2.2=56.73
{
double a;
double b;
double c;
a = (7.1);
b = (8.3);
c = (2.2);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << b << "\n" << endl;
cout << "- " << c << "\n" << endl;
cout << "------" << endl;
cout << setprecision(2) << (a*b)-c << "\n" << endl;
}
int calculation () // print to console: 3.2/(6.1*5.0)=0.10
{
double a;
double b;
double c;
a=(3.2);
b=(6.1);
c=(5.0);
cout << " " << fixed << setprecision (1) << a << "\n" << endl;
cout << b << "*" << c << endl; //how can I use variables instead of using quotes?
cout << "------" << endl;
cout << setprecision(2) << a/(b*c) << "\n" << endl;
system("PAUSE");
return 0;
}
What does this output error mean? How do I fix it? someone please explain this to me. Am I suppose to add: int calculate(int a, int b, int c)?
Output:
(32): error C4716: 'calculate' : must return a value
You've declared your function as one that returns an int value but there's no return statement. Try changing the declaration to void calculate() if you don't need to return a value from it.
The calculate function needs to return a value.
You need to add something like this at the end of calculate:
return (a*b)-c;
It's only because your calculate function is supposed to return an int
and there's no return in your function.
if you don't want to return anything, you can put void calculate() instead
I am new to C++ and this is like my first program I made and I used Visual C++ 2010 Express.
It is a weight conversion thing. There is an if loop, an else if loop and an else.
Here is the code:
#include <iostream>
using namespace std;
int main() {
float ay,bee;
char char1;
cout << "Welcome to the Ounce To Gram Converter" << endl << "Would you like to convert [O]unces To Grams or [G]rams To Ounces?" << endl;
start:
cin >> char1;
if (char1 = "G" ||"g"){
cout << "How many grams would you like to convert?" << endl;
cin >> bee;
cout << bee << " grams is equal to: " << bee*0.035274 << " ounces." << endl; goto start;
}
else if (char1 = "o"||"O"){
cout << "How many ounces would you like to convert" << endl;
cin >> ay;
cout << ay << " ounces is equal to: " << ay/0.035274 << " grams." << endl; goto start;
}
else{
cout << "Error 365457 The character you entered is to retarded to comprehend" << endl;
goto start;
}
cin.ignore();
cin.get();
return 0;
}
If I enter a "g", it executes this:
if (char1 = "G" ||"g"){
cout << "How many grams would you like to convert?" << endl;
cin >> bee;
cout << bee << " grams is equal to: " << bee*0.035274 << " ounces." << endl; goto start;
}
like it should
However, if I enter an "o", it executes this:
if (char1 = "G" ||"g"){
cout << "How many grams would you like to convert?" << endl;
cin >> bee;
cout << bee << " grams is equal to: " << bee*0.035274 << " ounces." << endl; goto start;
}
Instead of this:
else if (char1 = "o"||"O"){
cout << "How many ounces would you like to convert" << endl;
cin >> ay;
cout << ay << " ounces is equal to: " << ay/0.035274 << " grams." << endl; goto start;
}
Even if I put something random, like "h"
This Happens:
if (char1 = "G" ||"g"){
cout << "How many grams would you like to convert?" << endl;
cin >> bee;
cout << bee << " grams is equal to: " << bee*0.035274 << " ounces." << endl; goto start;
}
Instead of this:
else{
cout << "Error 365457 The character you entered is to retarded to comprehend" << endl;
goto start;
}
Please tell me what I did wrong.
char1 = "o"||"O" will always evaluate to true, because "O" is not null.
You want to use char1 == 'o' || char == 'O' and similar all over your if statements.
Note that = is assignment and == is an equality check. Use == when testing for equality and = when assigning. C and C++ allows you to use = in a check which returns the value of the assignment. This value is not 0, which evaluates to true and thus your if statement executes.