我的程序需要解析一个csv文件并确定缺失的数字组合。顺序无关紧要。为什么我的程序不能正常工作
该程序编译并运行,但打印出已打印在文件中的一行中的数字。
输入(mega2.csv):
123
134
142
注234
不在列表中。
预期输出: 程序应该输出234
因为它不是唯一使用的组合。相反,没有输出。
代码:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;
int main()
{
ifstream inFile;
string value;
string fileName;
int count;
int amount, playCount;
int a,b,c,d,e,f,g,h,i,j,k,l;
srand(time(0));
char ch;
do{
cout << "Enter number of plays (or -number to quit): ";
cin >> amount;
cout << endl;
playCount = 1;
while(playCount <= amount){
do{
inFile.open("mega2.csv");
//create random numbers a,b,c,d,e,f= mega num < 10
a = rand() % 5;
if(a == 0){a = 1;}
do{
b = rand() % 5;
if(b == 0){b = 1;}
}while(b == a);
do{
c = rand() % 5;
if(c == 0){c = 1;}
}while(c == a || c == b);
//Load numbers into g,h,i,j,k,l
do{
inFile >> g;
inFile.get(ch);
inFile >> h;
inFile.get(ch);
inFile >> i;
inFile.get(ch);
int count = 0;
cout << g << "," << h << "," << i << endl;
//A
if(a == g || a == h || a == i){
count++;
}
//B
if(b == g || b == h || b == i){
count++;
}
//C
if(c == g || c == h || c == i){
count++;
}
}// close second half do loop
while(inFile && count < 3);
inFile.close();
inFile.clear();
} // close whole do loop
while(count >= 3);
cout << endl;
cout << endl;
cout << endl;
cout << a << "," << b << "," << c << endl;
cout << endl;
playCount++;
} // End playCount while loop
}// End main do loop
while(amount >= 0); // quit program with negative number
system("pause");
return 0;
}
请修改您的问题以获得更具描述性的标题并删除无关的代码部分。发布之前,您应该运行您发布的确切代码,并确保问题发生在其中。 – 2012-03-10 07:28:11
你的标题看起来太含糊。 – 2012-03-10 07:29:03
“代码中有一些不必要的东西,它们不影响任何东西,只是忽略它们。”你如何删除不相关的部分,并提供给我们一个[简短,自包含,正确(可编译),例子](http://sscce.org/)?这会让StackOverflow社区更容易帮助你。另请参见http://tinyurl.com/so-hints – Johnsyweb 2012-03-10 07:37:14