assignment. Write a program that asks the user for a first

Write a program that asks the user for a first and last initial (1 character for each) that are separated by comma. Then the program asks the user for a 3 digit ID. Last, the program asks the user for 4 floating point numbers, separated by space. The 4 floating point numbers should be read in by using one C statement in the program.

The program prints to screen the user ID, followed by the first and last initials on one line. Then the program prints the header “Results” on the next line, and the 4 floating point numbers on the next 4 lines. The 4 floating point numbers should be right justified and printed with 2 digits after the decimal point. Run lab2.exe to see how the output should look.

To test the program, the 4 floating point numbers should be both small (under 10), and large (above 100), and with different number of digits after the decimal point. For example, use these 4 numbers: 123 45.678 .9 3.14159


c++

having trouble with this assignment
don't really understand how to do it, or start it
showing how to do it, explaining will help
So you're meant to do it in C or C++?

Do you have any knowledge of the languages?
in C
some
So what do you have so far?

You'll obviously need a main function, some variables to hold the user input, and some methods for verifying that input.

I'd suggest looking at printf() and scanf() documentation. The tutorials/documentation on this site are very much focussed on C++ - so I'd recommend looking at those found on http://cprogramming.com/ if you need reference (C Tutorial - C Made Easy is a good place to start).
/* This program will ask for a first and last name initial, a 3 digit ID, and for 4 floating point numbers.*/
/* Written by: */
/* Date: */

#include <stdio.h>

int main (void)
{
// local definitions
char first_initial = 'J';
char last_initial = 'G';
int id = 6711; // initializing the variable id
float fnum;


// statements
first_initial = 'J';
last_initial = 'G';

printf ("id is: %d\n", id);
printf ("first and last initials are:%c %c\n", first_initial, last_initial);


return 0;
}
Topic archived. No new replies allowed.