In: Computer Science
Define a struct computerType to store the following data about a computer: Manufacturer (50 character string), model type (50 character string), processor type (10 character string), ram (int) in GB, hard drive size (int) in GB, year when the computer was built (int), and the price (double).
Write a program that declares a variable of type computerType, prompts the user to the input data for the struct, and then outputs all the computer's data from the struct.
For Example:
Enter the name of the manufacturer: Dell Enter the model of the computer: Inspiron Enter processor type: I7 387 Enter the size of RAM (in GB): 32 Enter the size of hard drive (in GB): 512 Enter the year the computer was built: 1990 Enter the price: 1345.67 -------------------- Manufacturer: Dell Model: Inspiron Processor: I7 387 Ram: 32 Hard Drive Size: 512 Year Built: 1990 Price: $1345.67
#include <stdio.h> struct computerType { char manufacturer[50]; char model[50]; char processor[10]; int ram; int hardDrive; int year; double price; }; int main() { struct computerType ct; printf("Enter the name of the manufacturer: "); fgets(ct.manufacturer, 50, stdin); printf("Enter the model of the computer: "); fgets(ct.model, 50, stdin); printf("Enter processor type: "); fgets(ct.processor, 10, stdin); printf("Enter the size of RAM (in GB): "); scanf("%d", &(ct.ram)); printf("Enter the size of hard drive (in GB): "); scanf("%d", &(ct.hardDrive)); printf("Enter the year the computer was built: "); scanf("%d", &(ct.year)); printf("Enter the price: "); scanf("%lf", &(ct.price)); printf("\n--------------------\n"); printf("Manufacturer: %s", ct.manufacturer); printf("Model: %s", ct.model); printf("Processor: %s", ct.processor); printf("Ram: %d\n", ct.ram); printf("Hard Drive Size: %d\n", ct.hardDrive); printf("Year Built: %d\n", ct.year); printf("Price: $%.2lf\n", ct.price); return 0; }