So I first wanna point out that I'm extremely green when it comes to programming.
But Im trying to write this program that collects Atomic Element Information and prints it out. It works just fine until the last statement.
Atom is an integer, and Weight is a double. Everything else are just characters.
Code:
/*Program that collects and Displays Atomic Information
Written by Ben Freedgood
4-26-09
Language C: (gcc target)
*/
#include <stdio.h>
#include <conio.h>
typedef struct {
char name[20],symbol[5], member[100], shell[7];
int atom;
double weight;
}element_t;
int main(void)
{
element_t atom;
element_t name, symbol, member, shell;
element_t weight;
int h;
printf("\nWhat is the name of the element?");
gets(name.name);
printf("\nWhat is the symbol of the element?");
gets(symbol.symbol);
printf("\nWhat class is the element in?");
gets(member.member);
printf("\nWhat is the number of electrons in each shell?");
gets(shell.shell);
printf("\nWhat is the atomic number?");
scanf("f", &atom);
printf("\nWhat is the atomic weight?");
scanf("f", &weight);
printf("\n Name: %c", name.name);
printf("\n Symbol: %c", symbol.symbol);
printf("\n Class: %c", member.member);
printf("\n Electrons in Shell: %c", shell.shell);
printf("\n Atomic Number: %d", atom);
printf("\n Atomic Weight: %d", weight);
getch();
return(0);
}
The program compiles fine until it gets to weight. I tried switching out atom and weight, but after each prompt it prints out weird, yet strangely consistent symbols.
Example:
Code:
What is the atomic weight?
Name: P
Symbol: (Some symbol that looks like a crushed k)
Class:I
Electrons in Shell: (Two arrows pointing left and right)
Atomic Number: 2293536
Atomic Weight: 12
I have no freakin clue whats wrong here. Any help would be appreciated, I gotta have this in by tomorrow night.