Kexy Kathe Kexy Kathe - 22 days ago 6
C Question

Printing defined constants

#include<stdio.h>

#define UPPER 999999
#define LOWER 11111

int main(void)
{
// Local Declarations
double price = 89.99;
char grade = 'B';
int age = 97;

// Statements
printf("Homework 2:\n\nUsing printf\n");
printf(" age = %c, age\n");
printf("grade = %d, grade\n");
printf("price = %f, price\n\n");

printf("Using both printf and scanf\n");
printf("Enter a new value for age: ");
scanf("%d", &age);
printf("Enter a new value for grade: ");
scanf("%c", &grade);
printf("Enter a new value for price: ");
scanf("%lf", &price);

printf("Print the new values\n");
printf(" age = %d \n", age);
printf("grade = %c\n", grade);
printf("price = %lf\n\n", price);

print("\n\nPrinting two defined constants: "UPPER" and "LOWER"\n");
print("UPPER = %08d\n", UPPER);
print("LOWER = %08d\n", LOWER);



return 0;
} // end of main


Above is my programme and im supposed to fix it. I've been at it for almost 3 hours now still can figure out the problem. I've got a error and a few warnings.

warning: too few arguments for format|
several warning for the statements in the mid body

error: expected ')' before numeric constant|

this error is for printing two constants

Answer

You need to put your printf args outside of quotes.

Current:

//  Statements
printf("Homework 2:\n\nUsing printf\n");
printf("  age = %c, age\n");
printf("grade = %d, grade\n");
printf("price = %f, price\n\n");

Should be:

//  Statements
printf("Homework 2:\n\nUsing printf\n");
printf("  age = %c\n", age);
printf("grade = %d\n", grade);
printf("price = %f\n\n", price);
Comments