and step from there. The problem should show up after a couple of steps. Also...your formatting for the switch statement...seems rather odd to me. I would do something like:
Code:
switch (choice)
{
// accesses the functions
case 0:
Finished = 1;
break;
case 1:
addition(&reward);
break;
case 2:
subtraction(&reward);
break;
default :
printf("Error in input\n\n");
break;
}
Sure, it is more lines of code, but imagine each of the cases requiring 10 instructions. I think the way I have it above would be more clear. But, that is just a personal preference.
Last edited by Alterah; February 20th, 2012 at 01:38 AM.
At this point, I'd review how you created your "project": Is the file you are editing actually part of the project? Are you sure you are editing the correct "main.c"?
It sounds like your program is compiling, but not the file you are writing. that, or not running the proper objects.
When these errors come up, and especially on small scale projects, I recommend you use "rebuild everything", just to make sure.
Is your question related to IO?
Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
int main()
{
int foo;
bar();
}
void bar()
{
// I have no knowledge of "foo"
}
This is what the message is getting at. Are you able to step through the code at all? I was able to step through the code, fix the error I found with the debugger, and run your code.
One thing you can try is this:
File > New > Project > Console applicate > Run through the wizard, name your project. Then, you will have new project. Just copy and paste your code into the new main.c file of that project. Build it, and try debugging that. Like monarch dodra suggested, your project may be set up incorrectly.
Last edited by Alterah; February 20th, 2012 at 02:18 AM.
int main(){
do{
system("cls");
//Accept input from user
cout<<"Enter Employee ID: ";
getline(cin,E_code);
// opens file for input
ifstream inFile("employee.txt",ios::in);
// if input file can not be open enter the fail state
if(!inFile) {
cout << "Can not open input file" << endl;
cout << "The program will terminate" << endl;
system("pause");
exit(0);
}
//search for employee code
do{
getline(inFile,E_record);
int location = E_record.find(E_code);
Please format your code using [coe] tags as what you have posted is almost unreadable. use Go Advanced, select code then click '#'.
Help you about what? You haven't asked a question! If you want to convert this c++ code to c (why??) then as a starter for 10 you need to replace all references to the c++ classes (cin, cout, ifstream etc) with appropriate code using just the c library functions (printf, fread etc).
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
I just need someone who could help me about converting this C++ TO C FUNCTION.. this codes:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main(){
do{
system("cls");
//Accept input from user
cout<<"Enter Employee ID: ";
getline(cin,E_code);
// opens file for input
ifstream inFile("employee.txt",ios::in);
// if input file can not be open enter the fail state
if(!inFile) {
cout << "Can not open input file" << endl;
cout << "The program will terminate" << endl;
system("pause");
exit(0);
}
//search for employee code
do{
getline(inFile,E_record);
int location = E_record.find(E_code);
I just need someone who could help me about converting this C++ TO C FUNCTION.. this codes:
Please, never post unformatted code snippets! No one will read it because such a snippet is unreadable!
Didn't you read the answers to your first post here? For example, post#37?
Bookmarks