我似乎不明白为什么我得到一个:
Segmentation fault (core dumped)
Run Code Online (Sandbox Code Playgroud)
将我的"电影"输入电影结构时.这里有什么明显的逻辑错误或什么?
随着分段错误,我在for void循环中的for循环似乎只返回4个电影提示,因为#define NUM_MOVIES 5应该返回5.
万分感谢!
#include <iostream>
#include <string>
#include <sstream>
#define NUM_MOVIES 5
using namespace std;
struct movie{
string name[];
double copies[];
double rating[];
string description[];
string genre[];
} films [NUM_MOVIES];
void set_movies();
int which_movies_to_view();
int get_movies();
int rent_movie();
int printmovie();
int choice;
int main(){
set_movies();
which_movies_to_view();
get_movies();
rent_movie();
return 0;
}
void set_movies(){
movie set;
for(int i=0; i<NUM_MOVIES; i++){
cout << "Enter movie title: " << endl;
cin >> set.name[i];
cout << …Run Code Online (Sandbox Code Playgroud) 我无法理解为什么当我在代码中输入正常分数时,为什么我会得到无限值.除了GCD(最大公约数)之外的所有东西似乎都在起作用.
在这个地方有一个明显明显的逻辑错误吗?
我已经完成了我的研究并找到了问题的各种答案,我的意思是维基百科甚至给你编写代码,但是我想弄清楚如何使它按照我现在的编码方式工作.
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <math.h>
using namespace std;
class Fraction
{
private:
double num;
double den;
double fraction;
double temp;
public:
void setNum();
void setDen();
int getNum();
int getDen();
void lcdOutput();
void decOutput();
int gcd();
};
void Fraction::setNum(){
cout << "Enter a value for your numerator: " << endl;
cin >> num;
}
void Fraction::setDen(){
cout << "Enter a value for your denominator: " << endl;
cin >> den;
} …Run Code Online (Sandbox Code Playgroud)