0

Still holds. Don't hard-code 6 into your sortTable function. So, sortTable needs the number of teams. sortTable is called within calculateResults, which has no knowledge of numOfTeams either. How can we provide that knowledge? Pass numOfTeams into calculateResults as an extra parameter, then pass it into sortTable. I know you can do this. Go step by step. I cannot in good conscience keep translating these concepts into the code for you. This assignment is for your benefit.

I got it, and its kind of working, I have changed 6 into numOfTeams and now it adds team, shows the output:name goalsFor, goals against, etc. just have to go through the rest of the program to see if it works correctly. Thanks a lot for you help.I appreciate it.

0

does anyone know how to convert c program code into c++ program code? I have program written in c code, but need the same program and its functions in c++. I can post code if needed. Thanks.

hey,
you just need to replace #include<stdio.h> in C
by #include<iostream.h>
input method is also changed for eg:-scanf("%d",&f); with cin>>f;
output method:-for eg:-printf("%d",f); with cout<<f;
okay,,...........

0

hey , u cant jus user define " team Teams[xx]"!
there has to be an union (in case of C)
else u gotta use structure for user defined types..
or rather class could help out

0

does anyone know how to convert c program code into c++ program code? I have program written in c code, but need the same program and its functions in c++. I can post code if needed. Thanks.

Depending on the program, it could take a lot of work. C is not an object oriented language and C++ is. It makes all the difference in the world. The fundamental language is very similar but the program structure is very different. You need to be proficient in both languages to do the conversion.

0

hi there folks, my problem is working, but can anyone help me to put a dynamic array insted of the one I have at the moment.
heres the code:

#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 TeamInfo T;

void addTeam(T *, char[50], int);
//void addTeam(char[50], int);
void calculateResult(T *, int, int, int, int);
void sortTable(T[]);

int main(void)
{
 char newTeam[50];
 int menuChoice = 0;
 int numOfTeams = 0;
 int team1, team2, team1Score, team2Score;

 TeamInfo T[6]; //this is the array I have, but I need to change this one for a dynamic array....

	int i;
    while (menuChoice != 4)
	{
		cout << "*** SOCCER LEAGUE TABLE ***\n\n" << endl;
		cout << "1. Add new team\n" << endl;
		cout << "2. Display soccer league table\n" << endl;
		cout << "3. Add result or score\n" << endl;
		cout << "4. Quit the program\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)] = '\0';
				cin >> newTeam, sizeof(newTeam), stdin;
				newTeam[strlen(newTeam)] = '\0';
				addTeam(T, newTeam, numOfTeams);
				//numOfTeams++;
				cout << "\nNew team added\n" << endl;
				
                system("pause");
				system("CLS");
				numOfTeams++;
			}
		}		
		else if (menuChoice == 2)
		{
			cout << "Team Name\tPlayed\tWon\tDraw\tLost\tFor\tAgainst\t\tTotal\n" << endl;
			//cin.get();
			for ( i = 0; i < numOfTeams; i++)
			{
                i == numOfTeams;
				cout << T[i].name<<"\t\t"<<T[i].played<<"\t"<<T[i].won<<"\t"<<T[i].drawn<<"\t"<<T[i].lost<<"\t"<<T[i].goalsFor<<"\t"<<T[i].goalsAgainst<<"\t\t"<<T[i].points<<"\n\n\n"<< endl;
                cin >> T[i].name, T[i].played, T[i].won, T[i].drawn, T[i].lost, T[i].goalsFor, T[i].goalsAgainst, T[i].points;
                //system("pause"); 
                //cin.ignore();				
			}
		}
		else if (menuChoice == 3)
		{
			cout << "Enter first team playing the match:\n" << endl;
			cin >> team1;
			cout << "Enter second team playing the match:\n" << endl;
			cin >> team2;
			cout << "Enter first teams score:\n" << endl;
			cin >> team1Score;
			cout << "Enter second teams score:\n" << endl;
			cin >> team2Score;
			
			calculateResult(T , team1, team2, team1Score, team2Score);
		}
	}
 return 0;
}
  void addTeam(T* T, char *teamName, int i)
 {
    strcpy(T[i].name, teamName);
    T[i].points = 0;
	T[i].goalsFor = 0;
	T[i].goalsAgainst = 0;
	T[i].played = 0;
	T[i].won = 0;
	T[i].lost = 0;
	T[i].drawn = 0;  
 }

 void calculateResult(T* T, int t1, int t2, int t1R, int t2R)//, int i[])
 {
	if (t1R > t2R)
	{
		T[(t1-1)].points+=3;
		T[(t1-1)].won++;
		T[(t2-1)].lost++;	
	}
	else if (t2R > t1R)
	{
		T[(t2-1)].points+=3;
		T[(t2-1)].won++;
		T[(t1-1)].lost++;
	}
	else
	{
		T[(t2-1)].points++;
		T[(t1-1)].points++;
		T[(t1-1)].drawn++;
		T[(t2-1)].drawn++;
	}
	T[(t1-1)].goalsFor+=t1R;
	T[(t2-1)].goalsFor+=t2R;
	T[(t1-1)].goalsAgainst+=t2R;
	T[(t2-1)].goalsAgainst+=t1R;
	T[(t1-1)].played++;
	T[(t2-1)].played++;

	sortTable(T);
	
    int numOfTeams = 0;
 }

 void sortTable(T teams1[])
 {
    int numOfTeams = 0;
	T 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];
			}	
		} 
	}
 }

Edited by dinamit875: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.