C++ Latest Topics http://codedeception.net/ipb/index.php?/forum/61-c/C++ Latest TopicsenStructures homeworkhttp://codedeception.net/ipb/index.php?/topic/12999-structures-homework/ Ok, most of this code works.  I am just trying to make an exit procedure if they put in ZZ or zz for the first name.  I have tried a few different ways 

 

#include <stdio.h>
#include <string.h>

struct student{
    
    char f_name[20];
    char l_name[20];
    int id_num;
    float test1;
    float test2;
    float test3;
}s[10];

int main(void)

{

char ch;

float average;

int i;

for(i=0;i<=1;i++)
{
    printf("Enter first name(ZZ to quit): ");
    scanf("%s", &s.f_name);
    ch = s.f_name;
    if(ch== 'zz')
        break;
    else{
    printf("Enter last name: ");
    scanf("%s", &s.l_name);
    printf("Enter student ID number: ");
    scanf("%d", &s.id_num);
    printf("Enter the 3 test scores: ");
    scanf("%f %f %f", &s.test1, &s.test2, &s.test3);
    }
    
}
i--;
printf("Student\t\tStudent ID\tFinal Grade\n");
for(i;i>=0;i--)
{
average = (s.test1 + s.test2 + s.test3) / 3;     
printf("%s, %s\t%d\t\t%.2f\n", s.l_name, s.f_name, s.id_num, average);
}

return 0;

}

 

Everything works properly except the ZZ to quit.  If anyone could throw some help I would appreciate it, as always. 

Thanks

]]>
12999Wed, 11 May 2016 20:27:56 +0000
CS 101 Homework(C). Writing a sentence backwards.http://codedeception.net/ipb/index.php?/topic/12830-cs-101-homeworkc-writing-a-sentence-backwards/ I am attempting to make a program that rewrites a sentence backwards.  It is freezing up at the beginning of the for loop.  I am not sure if I am properly entering the array, or if the str[N] is even being recorded as an arrays through the gets function at the top.  Any help is appreciated. 

It is recording my str of i array as italics.  It is all supposed to be str[of i] but i changed it to j in the places it kept making it italics.  just pretend all the str[arrays] are str [ of i].

 

 

#include <stdio.h>
#include <string.h>

#define N 35
int main(void)

{
    char str[N];
    int i, j, temp;
    int length;

    printf("Enter a sentence up to %d characters long.\n", N);
    gets(str);
    printf("The sentence entered is: \n");
    puts(str); //Check to see if it is recording string.
    length = strlen(str);
    printf("%d", length);//Check to make sure it is recording the proper length
    for(i=0;i<length-1;i++)//Not sure if this is right.  I tried "for(i=length;i>=0;i--) and it froze up.
    {
       do
        {                       //Not sure if strings and arrays are mixed, if if str is being recorded as an array above.
        temp = str[j];             //Beginning at the for statement to the end of its loop is where I need help.
        str[j] = str[i+length-1];
        str[i+length-1] = temp;
        }
    }
    while{(str[i+length-1] !=str[j])}
    printf("%s", str);
    return 0;
}
 

]]>
12830Fri, 15 Apr 2016 00:59:13 +0000
Arrays in Chttp://codedeception.net/ipb/index.php?/topic/12570-arrays-in-c/ I am pretty new to programming.  I am taking my first CS class at college.  I am having trouble understanding arrays.  I am having trouble envisioning them.  I have looked on the internet and can't really find anything that will help me.

I am having trouble understanding the concept of creating something like array[ j ]

I am making something like

 

int main(void)

{

int array[5];

int i, j;

for(i=0;i<5;i++)

{

printf("Row %d: ", i+1);

for(j=0;j<5;j++)                /* I understand that this lets me enter 5 numbers */

                 {

                 scanf("%d", &array[ j ]);      /* Does this now mean that the array will be populated by j? */

                 }

}

Part of my homework is to make a 2 dimensional array that adds the rows and the columns.  I subscribe to chegg and have the answer below, but I am having a really hard time envisioning it and understanding it.  The rowsum = rowsum+array[j] and colsum=colsum[j]+array[j].

Above I am just trying to make a program that just add the rows up.  I understand the first for(i=0;i<5;i++) lets me enter 5 rows.  The for(j=0;j<5;j++) lets me enter 5 numbers in each row.  then the scanf("%d", &array[ j ]) populates the variable array with numbers from the variable j?

 

Below I think I understand it to the point of the for(i=0;i<5;rowsum=colsum=0,i++).  I assume that line means while i =0, and i < 5, rowsum of i equals colsum of i which is equal to 0, i++.  But I don't really understand that last part.  and I don't understand why they have the 2 following for statements after that line, or how the rowsum and colsum lines following those for statements work.  I don't understand how it is adding the individual numbers up.  I am having trouble with 1 dimensional arrays let alone 2 dimensional arrays.  If anyone can help me or direct me to a decent website that goes in depth into arrays, I would greatly appreciate it.  Thanks.

 

 

 

#include <stdio.h>

int main(void)

{
int i, j, array[5][5], rowsum[5],colsum[5];

for(i=0;i<5;i++)
    {
    printf("Enter row %d: ", i+1);
    for(j=0;j<5;j++)
        scanf("%d", &array[ i ][ j ]);
    }
    for(i=0;i<5;rowsum=colsum=0,i++);
    for(i=0;i<5;i++)
    for(j=0;j<5;j++)
    
    {
        rowsum[ i ]=rowsum[ i ]+array[ i ][ j ];
        colsum[ j ]=colsum[ j ]+array[ i ][ j ];
    }
    
    printf("\nRow Totals:    ");
        for(i=0;i<5;i++)
    printf("%d\t", rowsum);
    printf("\nColumn Totals: ");
        for(i=0;i<5;i++)
    printf("%d\t", colsum);
    printf("\n");
    
    return 0;
            


}

]]>
12570Thu, 10 Mar 2016 07:49:01 +0000
Arrays in Chttp://codedeception.net/ipb/index.php?/topic/12568-arrays-in-c/ double posted. oops.

]]>
12568Thu, 10 Mar 2016 04:09:17 +0000
C++ Primer, 5th Edition [DL]http://codedeception.net/ipb/index.php?/topic/8499-c-primer-5th-edition-dl/sup!

 

Would like to share the best book for learning C++ (at least for me, it's such a great book, i started with it and i'm still reading it). 

 

Also some links for online learning (can also be saved as pdf, with openoffice for example).

 

Here are the links:

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

Please login or register to see this link.

 

And here, finally, the download for C++ Primer:

 

Please login or register to see this link.



have fun with it :)

]]>
8499Fri, 13 Feb 2015 21:05:49 +0000
C++ wordlist creator (super fast)http://codedeception.net/ipb/index.php?/topic/12288-c-wordlist-creator-super-fast/ #include <iostream>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

int main()
{   // DATA ENTRY BEGIN --------------------------------------------------------
    system("cls");
    unsigned short int error=0;
    string poss;//POSSIBLE CHARACTER COMBINATIONS
    unsigned short int pass;//MAXIMUM PASSWORD LENGTH
    string password; //ACTUAL PASSWORD
    unsigned short int found=0;
    
    cout << "SELECT CHARACTER SET:\n\n";
    cout << "\t1. abcdefghijklmnopqrstuvwxyz\n";
    cout << "\t2. ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
    cout << "\t3. 0123456789\n\n";
    cout << "\t4. 1&2\n";
    cout << "\t5. 1&2&3\n";
    cout << "\t6. Other\n\t";
    cout << "----------------------------------\n\t";
    
    unsigned short int choice; // SELECTION FROM CHARACTER SET
    string dataset; //STRING FOR CHARACTER SET
    cin >> choice;    
    
    switch ( choice ) {
    
      case 1 :
        // Process for test = 1
        dataset="abcdefghijklmnopqrstuvwxyz";
        break;
    
      case 2 :
        // Process for test = 5
        dataset="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        break;
    
      case 3 :
        // Process for test = 5
        dataset="0123456789";
        break;
    
      case 4 :
        // Process for test = 5
        dataset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        break;
        
      case 5 :
        // Process for test = 5
        dataset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        break;
    
      case 6 :
        // Process for all other cases.
        cout << "\nENTER YOUR OWN CHARACTER SET: ";
        cin >> dataset;
        break;
        
      default :
        error=1;
    
    }
    if(error==0){
        poss=dataset;
        
        cout << "\nENTER PASSWORDS MAXIMUM LENGTH: ";
        cin >> pass;
        
        unsigned short int i=0;
        while(poss)
        {
                      i++;
        }
            
        int pass_array[pass-1];
        unsigned short int j=0;
        while(j<pass)
        {
                      pass_array[j]=0;
                      j++;
        }
        
        unsigned short int comb_max=i-1; // SIZE OF COMBINATIONS ARRAY
        signed short int pass_max=j-1; // MAXIMUM SIZE OF PASSWORD
        
        signed short int pointer; //POINTER WILL EQUAL THE CURRENT PASS SIZE
        // THIS ENABLES THE FLOATING POINT TO CHANGE THE COMBINATIONS
        
        unsigned int counter=0; // COUNTER FOR EACH COMBINATION TRY
        
        // DATA ENTRY END ----------------------------------------------------------
        
        // OPENS THE TEXT FILE TO WRITE PASSWORDS TO
        ofstream myfile;
        myfile.open ("c:\\passwords.txt");
        // -----------------------------------------    
        
        // ---- start timer ----
        time_t start,end;
        double dif;
        time (&start);
        
        while(pass_max>=0)
        {
        do
        {
                 pointer=pass_max;
                 while(pass_array[pointer]<=comb_max)
                 {
                                                     string curr;//  CURRENT PASSWORD TRY
                                                     counter++;
                                                     j=0;
                                                     while(j<=pass_max)
                                                     {
                                                                       curr+= poss[pass_array[j]];
                                                                       j++;
                                                     }
                                                     myfile << curr << " \n";
                                                     pass_array[pointer]=pass_array[pointer]+1;
                 }
                 pass_array[pointer]=0;
                 pointer--;
                 while(pass_array[pointer]==comb_max)
                 {
                                                     pass_array[pointer]=0;
                                                     pointer--;
                 }
                 pass_array[pointer]=pass_array[pointer]+1;
        }
        while(pointer>=0);
        
        pass_max--;
        }
        // ---- end timer ----
        end:
        time (&end);
        dif = difftime (end,start);
        
        // ---- close text file ---- //
        myfile.close();
        // ------------------------- //
        
        // ----- DISPLAY RESULTS ---- //
        unsigned int combinations_per_second;
        combinations_per_second=counter/dif;
        system("cls");
        cout << "\nWORDLIST CREATED";
        cout << "\n------------------------------";
        cout << "\nRUN TIME:\t " << dif << " sec";
        cout << "\nCOMBINATIONS:\t " << counter;
        cout << "\nCOMB/SEC: \t " << combinations_per_second;
        cout << "\n\n\n";
        system("pause");
        return 0;
    }else{
        cout << "\tINVALID CHOICE!";
        system("pause");      
    }   
}

]]>
12288Sun, 07 Feb 2016 14:02:55 +0000
I'm going crazy...Black Jack card game c++http://codedeception.net/ipb/index.php?/topic/6733-im-going-crazyblack-jack-card-game-c/Hello there boys and girls. I'm attempting to do a black jack card game.

My problem at the moment is that it won't continute looping through everything, after one loop. I want it to stop looping when the two bool variables, p1Ready and p2Ready, are false(You'll understand if you take a peek at the code). What I'm thinking is that I've never changed the bool variables to false but my while-loop keeps accepting the variables as false(?). I'm not sure if it's the bool variables fault or not but something is up and I'm not sure what it is.

Don't mind the comments, they are merely there to help me keep track of things.

 

This is my code at the moment, be aware that it isn't complete yet. Any comments or thoughts is much appreciated!

#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std;int main(){		srand(time(NULL));	//Variabler	int const CAP = 52;	int const PLAYERCAP = 2;	int cards[CAP];	bool p1Ready = true, p2Ready = true;	bool checkArray[CAP];	string players[PLAYERCAP];	int p1Points = 0, p2Points = 0, n, p1Wins = 0, p2Wins = 0;	char choice;	int counter = 0;	//Sätter värderna i cards - arrayen	for (int i = 0; i < 52; i = i + 4){		cards[i] = counter + 1;		cards[i + 1] = counter + 1;		cards[i + 2] = counter + 1;		cards[i + 3] = counter + 1;		counter++;	}	//Ger bool-arrayen checkArray "värdena" true	for (int i = 0; i < 52; i++){		checkArray[i] = cards[i];	}	cout << "Welcome to the cardgame Black Jack" << endl;	cout << "Please, enter the name of player 1" << endl;	cin >> players[0];	cout << "Please, enter the name of player 2" << endl;	cin >> players[1];	do{		//Här börjar spelare ett med att välja mellan att vilja ta ett kort eller inte		if (p1Ready == true){			cout << "Would you like a card, " << players[0] << "? (J/N)" << endl;			cin >> choice;			if (choice == 'J' || choice == 'j'){				n = rand() % 51;				while (checkArray[n] == false){					n = rand() % 51;					p1Points += cards[n];					cout << cards[n] << " is your cards value!" << endl;					cout << p1Ready;				}				cout << cards[n] << " is your cards value!" << endl;				p1Points += cards[n];				cout << "You now got a total of " << p1Points << " points" << endl;				cout << p1Ready;			}		}		else if (choice == 'N' || choice == 'n'){			cout << players[0] << "you decided that you didn't want to play anymore, " << p1Points << " points" << endl;			p1Ready = false;		}		//Här börjar spelare två med att välja mellan att vilja ta ett kort eller inte		if (p2Ready == true){			cout << "Would you like a card, " << players[1] << "? (J/N)" << endl;			cin >> choice;			if (choice == 'J' || choice == 'j'){				n = rand() % 51;				while (checkArray[n] == false){					n = rand() % 51;					p2Points += cards[n];					cout << cards[n] << " is your cards value!" << endl;					cout << p2Ready;				}				cout << cards[n] << " is your cards value!" << endl;				p2Points += cards[n];				cout << "You now got a total of " << p1Points << " points" << endl;				cout << p2Ready;			}		}		else if (choice == 'N' || choice == 'n'){			cout << players[1] << "you decided that you didn't want to play anymore, " << p2Points << " points" << endl;			p2Ready = false;		}	} while (p2Ready == false || p1Ready == false);	cout << "You decided you did not want to play anymore." << endl << endl;	cout << players[0] << " you won " << p1Wins << " time(s)." << endl << endl;	cout << players[1] << " you won " << p2Wins << " time(s)." << endl << endl;	return 0;}
]]>
6733Wed, 05 Nov 2014 18:24:41 +0000
My recent code in c++http://codedeception.net/ipb/index.php?/topic/7357-my-recent-code-in-c/#include

#include

class addition

{

public :

inline int sum(int m,int v) //inline

{

int f=m+v;

int *h; //pointer

h=&f;

return(*h);

}

inline float sum(float g,float n) //inline

{

float u=g+n; //pointer

float *k;

k=&u;

return(*k);

}

};

int main()

{

addition x;

int a=2,b=3;

float c=1.0000,d=2.0000;

clrscr();

cout<<"a+b="<

]]>
7357Tue, 09 Dec 2014 12:51:08 +0000
Need some help with c++ codehttp://codedeception.net/ipb/index.php?/topic/5974-need-some-help-with-c-code/Hello there, I got a problem which I hope you can help me with.

I would like to get the lowest score and the name of the one with the lowest score(score =  "total") to be written out.

I think I got it but the thing is that the last "player" always gets printed out as the one with the lowest score.

 

This is all of my code, don't mind the comments that I've made, they are just there to help me keep track of things.

#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std;int main(){    srand(time(NULL));    int dice1, dice2, DiceThrow, total = 0, minTotal = 0;    string name, exit, badLuckName;    cout << "We will now be playing \"Bad luck with dices\" " << endl;    cout << "How many throws with the dices? " << endl;    cin >> DiceThrow;    cout << endl;    do{        cout << "Your name: ";        cin >> name;        if (name != "exit")    { //Öppnar if            total = 0;            for (int i = 0; i < DiceThrow; i++)            {//öppnar for                dice1 = rand() % 6 + 1;                dice2 = rand() % 6 + 1;                total += dice1 + dice2;                minTotal = total;                cout << "Dice thrown: " << dice1 << " " << dice2 << " = " << dice1 + dice2 << endl;                            }//stänger for                        if (minTotal <= total)                        {                            minTotal = total;                            badLuckName = name;                        }            cout << "Total sum: " << total << endl << endl;    }//Stänger if                    //Startar om/avslutar do-loopen.    } while ( name != "exit"); //Kollar om man har skrivit "exit" som name och går då vidare till if-loopen    if (name == "exit")    {        cout << badLuckName<< " got the lowest score of: " << minTotal << "!" << endl; //Skriver ut den som har lägst poäng    }    return 0;}

any ideas? Help is HIGHLY appreciated.

 

*EDIT* I have no idea why the code is in different colours, I used the "<> - code" copy/paste thing, guess it's supposed to be like that with it.

]]>
5974Thu, 18 Sep 2014 12:35:01 +0000
A recommendation for a fantastic C++ book.http://codedeception.net/ipb/index.php?/topic/2130-a-recommendation-for-a-fantastic-c-book/This book gives you a solid understanding in C++ syntax, new C++0x features, when/how to use new/delete for memory allocations, and a ton of other things to numerous to even put into a post.

Anyways, here's the

Please login or register to see this link.

.

]]>
2130Sat, 27 Jul 2013 00:07:37 +0000
I would like to start to learn C++http://codedeception.net/ipb/index.php?/topic/4193-i-would-like-to-start-to-learn-c/Hello, Does anyone know any good resources to start learning C++ I have 0 understanding of it so I would like to learn how to read it and write it. Anyone know a good way to start off?


]]>
4193Mon, 14 Apr 2014 22:58:04 +0000
Introversion Games Source Packagehttp://codedeception.net/ipb/index.php?/topic/2305-introversion-games-source-package/Hi, Today I am releasing the source code to Introversion' games. These are mainstream games that have been sold and are still for sale and have generated thousands in sales, these sources are straight from their developer SVN

 

Games included:

Please login or register to see this link.

Please login or register to see this link.

and

Please login or register to see this link.

Please login or register to see this link.

 

 

]]>
2305Mon, 12 Aug 2013 18:10:40 +0000
Starting to Learn C++http://codedeception.net/ipb/index.php?/topic/1819-starting-to-learn-c/hey guys

Im am currently learning to code in c++ at beginner and am looking for people who can help with the learning process so if u have any good hints, tips, guides,  plz reply to this post as it will help me out alot and will help anyone else who is learning c++ on this forum 

 

thanks for reading and look forward to the comments and hopefully will turn out to be a big help

]]>
1819Fri, 21 Jun 2013 13:23:56 +0000