| | |
just a quick question here
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
0
#2 22 Days Ago
Well, C++ can compile almost any C code, except for a few minors differences. Post the code and I'll see.
I need pageviews! most fun profile ever :)
•
•
Join Date: Mar 2009
Posts: 25
Reputation:
Solved Threads: 0
0
#3 22 Days Ago
I know that c++ can compile most of c code, but i just need c++ code not c code heres the code:
I am trying to rewrite it into c++, but nothing good yet, i need to have same functions ect in c++.
C++ Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> void addTeam(char[50], int); void calculateResult(int, int, int, int); char newTeam[50]; int menuChoice = 0; int numOfTeams = 0; int team1, team2, team1Score, team2Score; typedef struct { char name[50]; int points, goalsFor, goalsAgainst, played, won, lost, drawn; } team; team teams[6]; void sortTable(team[]); int main(void) { int i; while (menuChoice != 4) { printf("Football League\n\n"); printf("1. Add team\n"); printf("2. Display league table\n"); printf("3. Add result\n"); printf("4. Quit\n"); scanf("%d", &menuChoice); if (menuChoice == 1) { if (numOfTeams == 6) printf("Error: Maximum amount of teams has been entered"); else { printf("Add new team\n"); fgets(newTeam, sizeof(newTeam), stdin); newTeam[strlen(newTeam)-1] = '\0'; fgets(newTeam, sizeof(newTeam), stdin); newTeam[strlen(newTeam)-1] = '\0'; addTeam(newTeam, numOfTeams); numOfTeams++; printf("\nNew team added\n"); } } else if (menuChoice == 2) { printf("\t\tP\tW\tD\tL\tF\tA\tT\n\n\n"); for ( i = 0; i < 6; i++) { printf("%s\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", teams[i].name, teams[i].played, teams[i].won,teams[i].drawn, teams[i].lost, teams[i].goalsFor, teams[i].goalsAgainst, teams[i].points); } } else if (menuChoice == 3) { printf("Enter first team playing:\n"); scanf("%d", &team1); printf("Enter second team playing:\n"); scanf("%d", &team2); printf("Enter first teams score:\n"); scanf("%d", &team1Score); printf("Enter second teams score:\n"); scanf("%d", &team2Score); calculateResult(team1, team2, team1Score, team2Score); } } return 0; } void addTeam(char *teamName, int i) { strcpy(teams[i].name, teamName); teams[i].points = 0; teams[i].goalsFor = 0; teams[i].goalsAgainst = 0; teams[i].played = 0; teams[i].won = 0; teams[i].lost = 0; teams[i].drawn = 0; } void calculateResult(int t1, int t2, int t1R, int t2R) { if (t1R > t2R) { teams[(t1-1)].points+=3; teams[(t1-1)].won++; teams[(t2-1)].lost++; } else if (t2R > t1R) { teams[(t2-1)].points+=3; teams[(t2-1)].won++; teams[(t1-1)].lost++; } else { teams[(t2-1)].points++; teams[(t1-1)].points++; teams[(t1-1)].drawn++; teams[(t2-1)].drawn++; } teams[(t1-1)].goalsFor+=t1R; teams[(t2-1)].goalsFor+=t2R; teams[(t1-1)].goalsAgainst+=t2R; teams[(t2-1)].goalsAgainst+=t1R; teams[(t1-1)].played++; teams[(t2-1)].played++; sortTable(teams); } void sortTable(team teams1[]) { team temp[1]; int i, j; for ( i = 0; i < 6; i++) { for ( j = 6; j >=0; j--) { if (teams1[j].points > teams1[(j-1)].points) { temp[1] = teams1[(j-1)]; teams1[(j-1)] = teams1[j]; teams1[j] = temp[1]; } } } }
0
#4 22 Days Ago
Just look up printing and getting input using cout<< and cin>>. Also, use
That seems to be the only things you really need to change on first glance.
I'm sure William or someone else will correct me if I'm wrong.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std;
I'm sure William or someone else will correct me if I'm wrong.
Last edited by Grn Xtrm; 22 Days Ago at 8:42 pm.
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
URL on facebook!
•
•
Join Date: Mar 2009
Posts: 25
Reputation:
Solved Threads: 0
0
#5 22 Days Ago
i have made those change to c code but getting another errors and here's the result:
C++ Syntax (Toggle Plain Text)
//#include <string.h> #include <iostream> #include <iomanip> #include <string> #include <stdio.h> using namespace std; struct TeamInfo { char name[50]; int points, goalsFor, goalsAgainst, played, won, lost, drawn; } typedef struct team; void addTeam(char[50], int); void calculateResult(int, int, int, int); void sortTable(team[]); //sortTable(team, teams1[]) int main(void) { char newTeam[50]; int menuChoice = 0; int numOfTeams = 0; int team1, team2, team1Score, team2Score; team teams[6]; int i; while (menuChoice != 4) { cout << "Football League\n\n" << endl; cout << "1. Add team\n" << endl; cout << "2. Display league table\n" << endl; cout << "3. Add result\n" << endl; cout << "4. Quit\n" << endl; cin >> menuChoice; if (menuChoice == 1) { if (numOfTeams == 6) cout << "Error: Maximum amount of teams has been entered" << endl; else { cout << "Add new team\n" << endl; cin.get(newTeam, sizeof(newTeam), stdin); newTeam[strlen(newTeam)-1] = '\0'; cin.get(newTeam, sizeof(newTeam), stdin); newTeam[strlen(newTeam)-1] = '\0'; addTeam(newTeam, numOfTeams); numOfTeams++; cout << "\nNew team added\n" << endl; } } else if (menuChoice == 2) { cout << "\t\tP\tW\tD\tL\tF\tA\tT\n\n\n" << endl; for ( i = 0; i < 6; i++) { cout << "%s\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", teams[i].name, teams[i].played, teams[i].won,teams[i].drawn, teams[i].lost, teams[i].goalsFor, teams[i].goalsAgainst, teams[i].points << endl; } } else if (menuChoice == 3) { cout << "Enter first team playing:\n" << endl; cin >> team1; cout << "Enter second team playing:\n" << endl; cin >> team2; cout << "Enter first teams score:\n" << endl; cin >> team1Score; cout << "Enter second teams score:\n" << endl; cin >> team2Score; calculateResult(team1, team2, team1Score, team2Score); } } void addTeam(char *teamName, int i) { strcpy(teams[i].name, teamName); teams[i].points = 0; teams[i].goalsFor = 0; teams[i].goalsAgainst = 0; teams[i].played = 0; teams[i].won = 0; teams[i].lost = 0; teams[i].drawn = 0; } void calculateResult(int t1, int t2, int t1R, int t2R) { if (t1R > t2R) { teams[(t1-1)].points+=3; teams[(t1-1)].won++; teams[(t2-1)].lost++; } else if (t2R > t1R) { teams[(t2-1)].points+=3; teams[(t2-1)].won++; teams[(t1-1)].lost++; } else { teams[(t2-1)].points++; teams[(t1-1)].points++; teams[(t1-1)].drawn++; teams[(t2-1)].drawn++; } teams[(t1-1)].goalsFor+=t1R; teams[(t2-1)].goalsFor+=t2R; teams[(t1-1)].goalsAgainst+=t2R; teams[(t2-1)].goalsAgainst+=t1R; teams[(t1-1)].played++; teams[(t2-1)].played++; sortTable(teams); } void sortTable(team teams1[]) { team temp[1]; int i, j; for ( i = 0; i < 6; i++) { for ( j = 6; j >=0; j--) { if (teams1[j].points > teams1[(j-1)].points) { temp[1] = teams1[(j-1)]; teams1[(j-1)] = teams1[j]; teams1[j] = temp[1]; } } } } return 0; }
0
#6 22 Days Ago
Can you post the errors being reported. Thanks.
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
URL on facebook!
•
•
Join Date: Mar 2009
Posts: 25
Reputation:
Solved Threads: 0
0
#7 22 Days Ago
this is updated code:
and these are the errors im gettin, look like it need a ";" or something like that???
In function `int main()':
33 elements of array `team teams[6]' have incomplete type In function `int main()':
33 storage size of `teams' isn't known
86 a function-definition is not allowed here before '{' token
86 expected `,' or `;' before '{' token
98 a function-definition is not allowed here before '{' token
98 expected `,' or `;' before '{' token
129 a function-definition is not allowed here before '{' token
129 expected `,' or `;' before '{' token
thanks
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include <string> #include <stdio.h> using namespace std; struct TeamInfo { char name[50]; int points; int goalsFor; int goalsAgainst; int played; int won; int lost; int drawn; }; typedef struct team; void addTeam(char[50], int); void calculateResult(int, int, int, int); void sortTable(team[]); int main(void) { char newTeam[50]; int menuChoice = 0; int numOfTeams = 0; int team1, team2, team1Score, team2Score; team teams[6]; int i; while (menuChoice != 4) { cout << "Football League\n\n" << endl; cout << "1. Add team\n" << endl; cout << "2. Display league table\n" << endl; cout << "3. Add result\n" << endl; cout << "4. Quit\n" << endl; cin >> menuChoice; if (menuChoice == 1) { if (numOfTeams == 6) cout << "Error: Maximum amount of teams has been entered" << endl; else { cout << "Add new team\n" << endl; cin >> newTeam, sizeof(newTeam), stdin; newTeam[strlen(newTeam)-1] = '\0'; cin >> newTeam, sizeof(newTeam), stdin; newTeam[strlen(newTeam)-1] = '\0'; addTeam(newTeam, numOfTeams); numOfTeams++; cout << "\nNew team added\n" << endl; } } else if (menuChoice == 2) { cout << "\t\tP\tW\tD\tL\tF\tA\tT\n\n\n" << endl; for ( i = 0; i < 6; i++) { cout << "%s\t\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", teams[i].name, teams[i].played, teams[i].won,teams[i].drawn, teams[i].lost, teams[i].goalsFor, teams[i].goalsAgainst, teams[i].points << endl; } } else if (menuChoice == 3) { cout << "Enter first team playing:\n" << endl; cin >> team1; cout << "Enter second team playing:\n" << endl; cin >> team2; cout << "Enter first teams score:\n" << endl; cin >> team1Score; cout << "Enter second teams score:\n" << endl; cin >> team2Score; calculateResult(team1, team2, team1Score, team2Score); } } void addTeam(char *teamName, int i) { strcpy(teams[i].name, teamName); teams[i].points = 0; teams[i].goalsFor = 0; teams[i].goalsAgainst = 0; teams[i].played = 0; teams[i].won = 0; teams[i].lost = 0; teams[i].drawn = 0; } void calculateResult(int t1, int t2, int t1R, int t2R) { if (t1R > t2R) { teams[(t1-1)].points+=3; teams[(t1-1)].won++; teams[(t2-1)].lost++; } else if (t2R > t1R) { teams[(t2-1)].points+=3; teams[(t2-1)].won++; teams[(t1-1)].lost++; } else { teams[(t2-1)].points++; teams[(t1-1)].points++; teams[(t1-1)].drawn++; teams[(t2-1)].drawn++; } teams[(t1-1)].goalsFor+=t1R; teams[(t2-1)].goalsFor+=t2R; teams[(t1-1)].goalsAgainst+=t2R; teams[(t2-1)].goalsAgainst+=t1R; teams[(t1-1)].played++; teams[(t2-1)].played++; sortTable(teams); } void sortTable(team teams1[]) { team temp[1]; int i, j; for ( i = 0; i < 6; i++) { for ( j = 6; j >=0; j--) { if (teams1[j].points > teams1[(j-1)].points) { temp[1] = teams1[(j-1)]; teams1[(j-1)] = teams1[j]; teams1[j] = temp[1]; } } } } return 0; }
In function `int main()':
33 elements of array `team teams[6]' have incomplete type In function `int main()':
33 storage size of `teams' isn't known
86 a function-definition is not allowed here before '{' token
86 expected `,' or `;' before '{' token
98 a function-definition is not allowed here before '{' token
98 expected `,' or `;' before '{' token
129 a function-definition is not allowed here before '{' token
129 expected `,' or `;' before '{' token
thanks
0
#8 22 Days Ago
You need to put return 0; at the end of main() and remove it from the end of the code. Remove the last 2 lines of the last code you posted.
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
URL on facebook!
0
#10 22 Days Ago
Don't put it after main() put it within main() just before the right brace that terminates main().
Check out my new band URL on facebook. I'm the bass player. :) Become a fan and leave comments if you like.
URL on facebook!
URL on facebook!
![]() |
Other Threads in the C++ Forum
- Previous Thread: C++ and CSV file
- Next Thread: Looping through the windows registry using RegEnumKeyEx till the leaves
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







