我需要制作一个程序,从用户那里得到一小部分,然后简化它.
我知道如何做,并完成了大部分代码,但我不断收到此错误"错误:预期未经过资格的ID'.' 令牌".
我已经声明了一个名为ReducedForm的结构,它包含简化的分子和分母,现在我想要做的是将简化值发送到这个结构.这是我的代码;
在Rational.h中;
#ifndef RATIONAL_H
#define RATIONAL_H
using namespace std;
struct ReducedForm
{
int iSimplifiedNumerator;
int iSimplifiedDenominator;
};
//I have a class here for the other stuff in the program
#endif
Run Code Online (Sandbox Code Playgroud)
在Rational.cpp中;
#include <iostream>
#include "rational.h"
using namespace std;
void Rational :: SetToReducedForm(int iNumerator, int iDenominator)
{
int iGreatCommDivisor = 0;
iGreatCommDivisor = GCD(iNumerator, iDenominator);
//The next 2 lines is where i get the error
ReducedForm.iSimplifiedNumerator = iNumerator/iGreatCommDivisor;
ReducedForm.iSimplifiedDenominator = iDenominator/iGreatCommDivisor;
};
Run Code Online (Sandbox Code Playgroud) 这是一个非常简单的程序我必须要做,但我对如何做到这一点空白.
基本上用户在mm/dd/yyyy中输入日期,我所要做的就是将值分开并在不同的行上输出.
这是我到目前为止:
int main ()
{
char cMonth[2];
char cDay [2];
char cYear[4];
cout << "Enter a date in the form mm/dd/yyy: " ;
cin.get(cMonth,3,'/');
cin.ignore(2,'/');
cin.get(cDay, 4, '/');
cin.ignore(2,'/');
cin.get(cYear, 5);
cout << cMonth << endl << cDay << endl << cYear << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的程序编译但是当它运行时它会输出错误的输出,例如,如果我04/13/2013输出的输出将是:
0413
13
2013
Run Code Online (Sandbox Code Playgroud)