Hello, I am writing a program for one of my classes and I've worked out all of the errors except one. I've spent the last hour trying to figure out what I've done wrong but I still can't. Any help would be greatly appreciated =)
Code:
#include <stdio.h>
int main()
{
float carbon_amu=12.011;
float hydrogen_amu=1.0079;
float oxygen_amu=15.9994;
float avogadros_number=6.02e23;
int number_of_carbon_atoms=0;
int number_of_hydrogen_atoms=0;
int number_of_oxygen_atoms=0;
float number_of_grams_of_molecule=0;
char molecule_name[80];
printf("What is the name of your CHO molecule? \n");
scanf("%s", &molecule_name);
printf("How many carbon atoms are in %s? \n", molecule_name);
scanf("%d", &number_of_carbon_atoms);
printf("How many hydrogen atoms are in %s? \n", molecule_name);
scanf("%d", &number_of_hydrogen_atoms);
printf("How many oxygen atoms are in %s? \n", molecule_name);
scanf("%d", &number_of_oxygen_atoms);
printf("How many grams of %s do you have?\n", molecule_name);
scanf("%f", &number_of_grams_of_molecule);
float carbon_mass_per_mole=number_of_carbon_atoms*carbon_amu;
float hydrogen_mass_per_mole=number_of_hydrogen_atoms*hydrogen_amu;
float oxygen_mass_per_mole=number_of_oxygen_atoms*oxygen_amu;
float molecule_mass_per_mole=carbon_mass_per_mole+hydrogen_mass_per_mole+oxygen_mass_per_mole;
float number_of_molecules=number_of_grams_of_molecule/molecule_mass_per_mole*avogadros_number;
printf(" \n");
printf("Results:\n");
printf("--------\n");
printf("The mass of carbon in %f is:\n", carbon_mass_per_mole);
printf("The mass of hydrogen in %f is:\n", hydrogen_mass_per_mole);
printf("The mass of oxygen in %f is:\n", oxygen_mass_per_mole);
printf("--------------------------------------------------------\n");
printf("The number of %s molecules in %f grams is %f\n", molecule_name, number_of_grams_of_molecule, number_of_molecules);
}
The error that I have been getting is:
a03.c: In function 'main':
a03.c:25:4: warning: format '%s' expects type 'char *', but argument 2 has type 'char (*)[80]'
Thanks again in advance!