d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C Programming Basic! Help! > Needing Help With C Program
12Next
Add Reply New Topic New Poll
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 11 2013 01:50pm
possibly want this 3 hours from now if possible
i have a 2 tests tomorrow that i never knew about and i need time to study. the sooner I get answers the more I can study
if you could provide solutions and possibly some explanations to help this along
.

3. Create a counting program that prompts the user for three
inputs (shown next) that determine how and what to count.
Store the user’s answers in variables. Use the acquired data to
build your counting program with a for loop and display the
results to the user.
• Beginning number to start counting from
• Ending number to stop counting at
• Increment number

4. Create a math quiz program that prompts the user for how many
questions to ask. The program should congratulate the player if
he or she gets the correct answer or alert the user of the correct
answer in the event the question is answered incorrectly.
The math quiz program should also keep track of how many
questions the player has answered correctly and incorrectly and
display these running totals at the end of the quiz.

5. Modify the Concentration Game to use a main menu. The menu
should allow the user to select a level of difficulty and/or quit
the game (a sample menu is shown below). The level of difficulty
could be determined by how many separate numbers the user
has to concentrate on and/or how many seconds the player has
to concentrate. Each time the user completes a single game of
Concentration, the menu should reappear allowing the user to
continue at the same level, at a new level, or simply quit the
game.
1 Easy (remember 3 numbers in 5 seconds)
2 Intermediate (remember 5 numbers in 5 seconds)
3 Difficult (remember 5 numbers in 2 seconds)
4 Quit

This is the concentration game I need help modifying

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main()
{
char cYesNo = '\0';
int iResp1 = 0;
int iResp2 = 0;
int iResp3 = 0;
int iElaspedTime = 0;
int iCurrentTime = 0;
int iRandomNum = 0;
int i1 = 0;
int i2 = 0;
int i3 = 0;
int iCounter = 0;
srand(time(NULL));
printf("\nPlay a game of Concentration? (y or n): ");
scanf("%c", &cYesNo);
if (cYesNo == 'y' || cYesNo == 'Y') {
i1 = rand() % 100;
i2 = rand() % 100;
i3 = rand() % 100;
printf("\nConcentrate on the next three numbers\n");
printf("\n%d\t%d\t%d\n", i1, i2, i3);
iCurrentTime = time(NULL);
do {
iElaspedTime = time(NULL);
} while ( (iElaspedTime - iCurrentTime) < 3 ); //end do while loop
system ("cls");
printf("\nEnter each # separated with one space: ");
scanf("%d%d%d", &iResp1, &iResp2, &iResp3);
system("pause");
if ( i1 == iResp1 && i2 == iResp2 && i3 == iResp3 )
printf("\nCongratulations!\n");
else
printf("\nSorry, correct numbers were %d %d %d\n", i1, i2, i3);
system("pause");
} //end if
} //end main function
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 11 2013 01:55pm
Use code brackets.
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 11 2013 04:24pm
this is for C programming ^ that is correct coding and its 100% correct however not for question 5 since its not modified
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 11 2013 05:19pm
Quote (Xarai @ Feb 11 2013 06:24pm)
this is for C programming ^ that is correct coding and its 100% correct however not for question 5 since its not modified


he meant insert them into the forumes "code" brackets so it is easier to read and maintains its indentation.
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 12 2013 12:28pm
this is how it looks when it's in the program so what do u mean? give an example cause now im lost
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 12:54pm
Quote (Xarai @ Feb 12 2013 02:28pm)
this is how it looks when it's in the program so what do u mean? give an example cause now im lost


Code
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define true 0
#define false 1

_Bool isString(char *dataArray);

int main()
{
   char stringArray[50];
   char *morseArray[27] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
   int i = 0;

   printf("Please insert a string.\n");
   fgets(stringArray, 49, stdin);

   if(isString(stringArray) == true)
   {
       //printf("This is a string.\n");
       while(stringArray[i] != '\0')
       {
           if(morseArray[(int)toupper(stringArray[i]) - (int)'A'] != '\0')
           {
               printf("%s ", morseArray[(int)toupper(stringArray[i]) - (int)'A']);
           }

           i++;
       }
   }
   else
   {
       printf("This is not a string.\n");
   }

   getchar();
   return 0;
}

_Bool isString(char *dataArray)
{
   for(int i = 0; i < sizeof(dataArray) - 1; i++)
   {
       if((int)dataArray[i] < 65 || (int)dataArray[i] > 90)
       {
           return false;
       }
   }

   return true;
}


this is how code looks inside the forums [code] tags

it keeps its indentation and is easier to read because of a font change.
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 12 2013 01:06pm
Code
#include <stdio.h>
/********************************************
FUNCTION PROTOTYPES
********************************************/
int sportsQuestion(void);
int geographyQuestion(void);
void pause(int);
/*******************************************/

/********************************************
GLOBAL VARIABLE
********************************************/
int giResponse = 0;
/*******************************************/
main()
{
do {
system("clear");
printf("\n\tTHE TRIVIA GAME\n\n");
printf("1\tSports\n");
printf("2\tGeography\n");
printf("3\tQuit\n");
printf("\n\nEnter your selection: ");
scanf("%d", &giResponse);
switch(giResponse) {
case 1:
if (sportsQuestion() == 4)
printf("\nCorrect!\n");
else
printf("\nIncorrect\n");
pause(2);
break;
case 2:
if (geographyQuestion() == 2)
printf("\nCorrect!\n");
else
printf("\nIncorrect\n");
pause(2);
break;
} //end switch
} while ( giResponse != 3 );
} //end main function
/**********************************************************
FUNCTION DEFINITION
**********************************************************/
int sportsQuestion(void)
{
int iAnswer = 0;
system("clear");
printf("\tSports Question\n");
printf("\nWhat University did NFL star Deon Sanders attend? ");
printf("\n\n1\tUniversity of Miami\n");
printf("2\tCalifornia State University\n");
printf("3\tIndiana University\n");
printf("4\tFlorida State University\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
} //end sportsQuestion function
/**********************************************************
FUNCTION DEFINITION
**********************************************************/
int geographyQuestion(void)
{
int iAnswer = 0;
system("clear");
printf("\tGeography Question\n");
printf("\nWhat is the state capitol of Florida? ");
printf("\n\n1\tPensecola\n");
printf("2\tTallahassee\n");
printf("3\tJacksonville\n");
printf("4\tMiami\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
} //end geographyQuestion function
/***********************************************************
FUNCTION DEFINITION
************************************************************/
void pause(int inNum)
{
int iCurrentTime = 0;
int iElapsedTime = 0;
iCurrentTime = time(NULL);
do {
iElapsedTime = time(NULL);
} while ( (iElapsedTime - iCurrentTime) < inNum );
} // end pause function
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 12 2013 01:38pm
do you actually code without indentation?
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Feb 12 2013 01:54pm
Quote (AbDuCt @ Feb 12 2013 11:38am)
do you actually code without indentation?


:lol:
Member
Posts: 51
Joined: Feb 7 2013
Gold: 0.00
Feb 12 2013 02:02pm
yup XD i can see why my teacher is annoyd at me now XD
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll