1994 && modelYear 2003 && modelYear < 2007 )){ printf("RECALL"); }else{ }Need help with this c code?ok so here's what I have to do: Define a structure type element_t to represent one element from the pe" /> I Need Help With This C Code.

TRENDING NEWS

POPULAR NEWS

I Need Help With This C Code.

Need help with c code?

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message "RECALL" to standard output if the value of modelYear falls within those two ranges.

Tried:

if((modelYear > 1994 && modelYear 2003 && modelYear < 2007 )){
printf("RECALL");
}else{

}

Need help with this c code?

ok so here's what I have to do:

Define a structure type element_t to represent one element from the periodic table of elements. Components should include the atomic number (an integer); the name, chemical symbol, and class (strings); a numeric field for the atomic weight; and a seven element array of integers for the number of electrons in each shell. the following are the components of an element_t structure for sodium. 11 sodium Na alkali_metal 22.9898 2 8 1 0 0 0 0 Define and test I/O functions scan_element and print_element.

When i compile and test the program, everything works perfectly fine except for the array that shows the number of electrons in each shell. It gives me another array of numbers instead of 281000. This is what it gives me: 11 Sodium Na alkali_metal 22.989800 363696

I would really appreciate any help, Thanks!!

#include
#define ELEM_NAME 15
#define ELEM_CLASS 20
#define ELECT 10

typedef struct
{
int atom_num;
char name[ELEM_NAME];
char symbol[3];
char class_of_metal [ELEM_CLASS];
double atomic_weight;
int elec[ELECT];
} element_t;

/*element_t scan_element();

void print_element(element_t my_element);

element_t

scan_element();*/

int main(void)
{

element_t my_element;
printf("enter the atomic number:\n");
scanf("%d", &my_element.atom_num);

printf("enter element name:\n");
scanf("%s", my_element.name);

printf("enter symbol:\n");
scanf("%s", my_element.symbol);

printf("enter type of metal:");
scanf("%s", my_element.class_of_metal);

printf("enter atomic weight:");
scanf("%lf", &my_element.atomic_weight);

printf("enter number of electrons in each shell:");
scanf("%d", my_element.elec);
/* output info */
printf("%d %s %s %s %lf %d", my_element.atom_num,
my_element.name,
my_element.symbol,
my_element.class_of_metal,
my_element.atomic_weight,
my_element.elec[ELECT]);

return (0);
}

Which websites should I go to if I need help with my code in C++?

I'm going to give an unconventional answer here.  My answer is:  None.   If you have the patience and discipline, pick up any highly-rated C++ book and read it.  Most people spend too much time learning meta-topics around coding instead of actually doing it.   After reading the book(s) and doing many code exercises, you'll find that you won't have these pesky questions anymore because you will have answered them yourself.   If you depend greatly on a website to make forward progress in your project, you are in the wrong business or you (or your school) are using the wrong language.

I need help with this C Program!!?

Hi,

The original code has a lot of switch/case statements that seem replaceable with some 'shorter' logic. Here is another alternative:

#include
#include
#include
#include
#include

// enum Choice { Rock = 0, Paper, Scissors }; // Rock=0, Paper=1, Scissors=2
const char * picks[] = {"Rock", "Paper", "Scissors"};

// ========================================...
void CheckWinner(int PlayerChoice) {

int random = rand()%3;

printf("Computer: %s\n", picks[random]);
if(PlayerChoice == random) {
printf("Draw\n\n");
}
else {
printf("%s Wins!\n",((PlayerChoice + 1) % 3 == random) ? "Computer" : "Player");
}
return;
}

// ========================================...
char DoMenu() {
char MenuChoice;

printf("(R)ock, (P)aper, (S)cissors, (Q)uit\n");
printf("----------\n");
printf("Choice: ");
// MenuChoice = getchar();
scanf(" %c", &MenuChoice);
printf("\n");

return ((char) toupper(MenuChoice)); // make uppercase
}

// ========================================...
int main(int argc, const char * argv[]) {
int PlayerChoice;
char choice;

// initialize the computer's random number generator
srand(time(0));
while((choice = DoMenu()) != 'Q') {
// printf("c = %c or %d\n", choice, (int) choice);
PlayerChoice = (choice == 'R') ? 0 : ((choice == 'P') ? 1 : 2);
printf("Player = %s\n", picks[PlayerChoice]);
CheckWinner(PlayerChoice);
printf("\n\n");
}
// end program
return 0;
}

Need help understanding this piece of C code?

I am trying to learn how to program an ARM based microcontroller using C and I came across a simple blinky program. Here is the very beginning for the code:

void Delay(__IO uint32_t nCount)
{
while(nCount--)
{
}
}

...later in the program this delay function is called as follow:
Delay(0xFFFFF);


I understand that it is a delay function that takes one value as its parameter, but there are a lot of stuff I still don't quite understand...
1) What is "__IO"? It doesn't look like a type nor variable to me.
2) For "unit32_t", I understand that "unit32" alone is use to declare a 32 bits unsigned integer type of variable, but what is does the "_t" do exactly?
3) The while() function loops till nCount reaches 1, right?
4) Can I use Delay(1048575) instead of Delay(0xFFFFF)?
5) How do I translate how many second this delay is going to take? Does it has to do with the clock speed and knowing how many clock cycles does the while() function takes?
6) I believe this is an inefficient way to introduce a delay, because the MCU could be doing other stuffs. A better way is probably to use a timer and once the time expired the function shall trigger an interrupt. Am I right?

Thank you so much! I am an EE student and trying to self-learn embedded programming but it is a lot harder than I thought haha...

The full code can be found here:
http://myembeddedtutorial.blogspot.com/2...

Need help with phone program in C++?

Thanks for the code. The main algorithm should fill a char array with the following format and return it:

[1] [-] [8][0][0] [-] [ ][ ][ ] [-] [ ][ ][ ][ ]['\0'] //only numeric char: 0-9

For each alphabet char in "NEED CAR", convert to lower case (e.g. if user enters a mixture of cases), then for each character use a switch statement to test within which ascii value it falls, and fill your main array (the one that you will be returning as answer).

Your code wasn't working on my end, so I had to get it to a running version, I didn't write the main algorithm here:

#include
#include
using namespace std;

int main()
{
char option;
char phoneNum[32], tokBuffer[12];
char* pointerToTok;

do
{
cout << "\nEnter a phone number(with text): ";
cin.getline(phoneNum, 32);

cout << phoneNum << endl;

pointerToTok = strtok(phoneNum, "-");


while(pointerToTok != NULL)
{
strcpy(tokBuffer, pointerToTok);
cout << "\ntokens = " << tokBuffer << endl;

//Code to convert tokBuffer[] to another char array
//but with format 1-800-###-####

//Move to next token
pointerToTok = strtok(NULL, "-");
}

cout << "\nNo more tokens found, would you like to continue (y/n)? ";
cin >> option;

//When I remove those, program won't accept a 2nd input
cin.clear();
cin.ignore();

} while((option != 'n') && (option != 'N'));

return 0;
}

Can anyone help me with C++?

I’m sure somebody will, but that’s not going to do you any good.It’s really important that you do your own homework.

Need Help with making an enum statements in C code?

Write an enum statement with no tag that will define left_serve to be 0, right_serve to be 1, moving_left to be 2 and moving_right to be 3.


I have tried

typedef enum {left_serve=0, right_serve=1, moving_left=2, moving_right=3};

and

enum {left_serve=0, right_serve=1, moving_left=2, moving_right=3};

I need to write a C code for Cholesky decomposition. Who can help me?

Cholesky decompositionC, specifically:Cholesky decomposition

Can anyone please help me code a polygon in C++?

Try These..double polygon_area(int actual_size, double x[], double y[])
{
printf("In polygon.area\n");
double area = 0.0;
for (int i = 0; i < actual_size; ++i)
{
int j = (i + 1)%actual_size;
area += 0.5 * (x[i]*y[j] - x[j]*y[i]);
}
printf("The area of the polygon is %lf \n", area);
return (area);
}
Hope These May Help You..!!!

TRENDING NEWS