Re: C++/C conversion to just C
Set a break point at
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.
Re: C++/C conversion to just C
But in my watches all it says is
Function arguements
Finished = no symbol "finished" in current context
choice = no symbol.... etc.
what is that telling me?? i declared them they are symbolizing something, so it should work right?
Re: C++/C conversion to just C
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.
Re: C++/C conversion to just C
Consider the following:
Code:
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.
Re: C++/C conversion to just C
ok the problem was just at the while loop. had to get rid of ; and made it == instead of =. fml hahahaha.
well thank you everyone for coming on this journey with me. Conversion to C using pointers success!
On a final note does anyone know how to make the case selection letter selection like A) B) C) instead of 1 2 3 ?
Re: C++/C conversion to just C
Hello..good day..can you help me,about this? c++ to c...
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;
void EmployeeInfo ();
void input();
void printstars ();
void paycompute();
void date_coverage();
//global variables
string E_code,E_name,E_record,E_level,d_coverage;;
double perday,T_Hours,T_Mins;
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);
if(location>0)
{
E_code = E_record.substr(location,8);
E_level = E_record.substr(E_record.length()-1,1);
E_name = E_record.substr(0,location-1);
break;
}
}while(!inFile.eof());
if (E_level =="1") perday = 380;
if (E_level =="2") perday = 450;
if (E_level =="3") perday = 550;
//Display Records
if (E_name==""){
cout<<"Record not Found!\n\n\n";
system("pause");
exit(0);
}
else {
EmployeeInfo ();
input();
date_coverage();
EmployeeInfo ();
paycompute();
cout<<"\n\n";
system("Pause");
}
}while(true);
}//END
//MY USER-DEFINED FUNCTIONS
void EmployeeInfo (){
system("cls");
printstars ();
cout<<"\n\nEmployee Name :\t"<<E_name;
cout<<"\nEmployee Code :\t"<<E_code;
cout<<"\nEmployee Level:\t"<<"Level "<<E_level;
cout<<"\nEmployee Rate :\t"<<"Php"<<perday<<".00/day";
printstars ();
}
void input ()
{
// declare variables --------
int hrs_in[5],hrs_out[5], min_in[5],min_out[5],x,TH_inout[5];
char colon;
string days []={"Monday","Tuesday","Wednesday","Thursday","Friday"};
// accept input -------
cout<<"\n\nEnter the time using the following format(hour:minutes)\n";
for(x=0;x<5;x++){
cout<<"\n\nEnter Log-in for "<<days[x]<<" : ";
cin>>hrs_in[x]>>colon>>min_in[x];
cout<<"Enter Log-out for "<<days[x]<<" : ";
cin>>hrs_out[x]>>colon>>min_out[x];
}
//write data to text files ------------
ofstream out("dtr.txt",ios::out);
out<<E_code;
for(x=0;x<5;x++){
out<<","<<hrs_in[x]<<":"<<min_in[x]<<","<<hrs_out[x]<<":"<<min_out[x];
} // out<<"\n\nTotal Working Hours: "<<T_Hours<<" Hrs";
cout<<"Files successfully written to dtr.txt files!";
cout<<"\n\n";
system("pause");
//compute number of Total Hours and Minutes --------
for(x=0;x<5;x++){
if(hrs_in[x]<8)
{hrs_in[x]=8;
min_in[x]=00;
}
if(hrs_in[x]>=12 && hrs_in[x]<13)
{
hrs_in[x]=13;
min_in[x]=00;
}
if(hrs_in[x]>=12 && hrs_in[x]<=13)
{TH_inout[x] = (hrs_out[x]-hrs_in[x]);}
else
{TH_inout[x] = (hrs_out[x]-hrs_in[x])-1;}
T_Hours =T_Hours+TH_inout[x];
}
}
void printstars (){
cout<<"\n=================================================";
}
void date_coverage(){
system("cls");
printstars();
cout<<"\nEnter Payroll Date of Coverage: ";
getline(cin,d_coverage);
getline(cin,d_coverage);
}
void paycompute(){
cout<<"\n\nDate of Coverage\t: "<<d_coverage;
cout<<"\nTotal Work Hours\t: "<<T_Hours<<".00 Hrs";
cout<<"\nWeekly Regular Salary\t: "<<"Php"<<((T_Hours/8)*perday)<<".00";
cout<<"\n";
printstars ();
cout<<"\n\n";
}
thanks
Re: C++/C conversion to just C
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).
Re: C++/C conversion to just C
Quote:
Originally Posted by
Charmmanuel
Hello..good day..can you help me,about this? c++ to c...
Did you read the whole thread? :confused:
There is a lot of opinions what and how to achieve it. What is the problem?
Re: C++/C conversion to just C
hello.. Im still a student... I need help on that code..to make it c function not c++ ..
Re: C++/C conversion to just C
Quote:
Originally Posted by
Charmmanuel
hello.. Im still a student... I need help on that code..to make it c function not c++ ..
I am confused...
What happens? "still a student" cannot read? "still a student" has no idea how tocompile C file? :confused:
Re: C++/C conversion to just C
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;
void EmployeeInfo ();
void input();
void printstars ();
void paycompute();
void date_coverage();
//global variables
string E_code,E_name,E_record,E_level,d_coverage;;
double perday,T_Hours,T_Mins;
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);
if(location>0)
{
E_code = E_record.substr(location,8);
E_level = E_record.substr(E_record.length()-1,1);
E_name = E_record.substr(0,location-1);
break;
}
}while(!inFile.eof());
if (E_level =="1") perday = 380;
if (E_level =="2") perday = 450;
if (E_level =="3") perday = 550;
//Display Records
if (E_name==""){
cout<<"Record not Found!\n\n\n";
system("pause");
exit(0);
}
else {
EmployeeInfo ();
input();
date_coverage();
EmployeeInfo ();
paycompute();
cout<<"\n\n";
system("Pause");
}
}while(true);
}//END
//MY USER-DEFINED FUNCTIONS
void EmployeeInfo (){
system("cls");
printstars ();
cout<<"\n\nEmployee Name :\t"<<E_name;
cout<<"\nEmployee Code :\t"<<E_code;
cout<<"\nEmployee Level:\t"<<"Level "<<E_level;
cout<<"\nEmployee Rate :\t"<<"Php"<<perday<<".00/day";
printstars ();
}
void input ()
{
// declare variables --------
int hrs_in[5],hrs_out[5], min_in[5],min_out[5],x,TH_inout[5];
char colon;
string days []={"Monday","Tuesday","Wednesday","Thursday","Friday"};
// accept input -------
cout<<"\n\nEnter the time using the following format(hour:minutes)\n";
for(x=0;x<5;x++){
cout<<"\n\nEnter Log-in for "<<days[x]<<" : ";
cin>>hrs_in[x]>>colon>>min_in[x];
cout<<"Enter Log-out for "<<days[x]<<" : ";
cin>>hrs_out[x]>>colon>>min_out[x];
}
//write data to text files ------------
ofstream out("dtr.txt",ios::out);
out<<E_code;
for(x=0;x<5;x++){
out<<","<<hrs_in[x]<<":"<<min_in[x]<<","<<hrs_out[x]<<":"<<min_out[x];
} // out<<"\n\nTotal Working Hours: "<<T_Hours<<" Hrs";
cout<<"Files successfully written to dtr.txt files!";
cout<<"\n\n";
system("pause");
//compute number of Total Hours and Minutes --------
for(x=0;x<5;x++){
if(hrs_in[x]<8)
{hrs_in[x]=8;
min_in[x]=00;
}
if(hrs_in[x]>=12 && hrs_in[x]<13)
{
hrs_in[x]=13;
min_in[x]=00;
}
if(hrs_in[x]>=12 && hrs_in[x]<=13)
{TH_inout[x] = (hrs_out[x]-hrs_in[x]);}
else
{TH_inout[x] = (hrs_out[x]-hrs_in[x])-1;}
T_Hours =T_Hours+TH_inout[x];
}
}
void printstars (){
cout<<"\n=================================================";
}
void date_coverage(){
system("cls");
printstars();
cout<<"\nEnter Payroll Date of Coverage: ";
getline(cin,d_coverage);
getline(cin,d_coverage);
}
void paycompute(){
cout<<"\n\nDate of Coverage\t: "<<d_coverage;
cout<<"\nTotal Work Hours\t: "<<T_Hours<<".00 Hrs";
cout<<"\nWeekly Regular Salary\t: "<<"Php"<<((T_Hours/8)*perday)<<".00";
cout<<"\n";
printstars ();
cout<<"\n\n";
}
Re: C++/C conversion to just C
Quote:
Originally Posted by
Charmmanuel
I just need someone who could help me about converting this C++ TO C FUNCTION.. this codes:
:mad:
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?