Note that there are some explanatory texts on larger screens.

plurals
  1. POAn assignment requires that I gather a name with 2 scanf's
    primarykey
    data
    text
    <p>So here is my first ultra beginner computer programming question in C.</p> <p>I need to set it up so that someone can type in their full name on the input. Here is part of the specs - </p> <blockquote> <p>"You'll have to do a little thinking to figure out how to get the printed names lined up with all the other columns. The first hint is that it involves joining strings together, something called concatenation. Give it a go, and if you can't figure it out, look at the next document in this folder; it contains additional hints. Part of the purpose of this assignment is to implicitly teach you concatenation. Do NOT use tabs (\t) and make sure your C/C++ editor does not produce tab characters.</p> <p>Do NOT use gets() in this program. Use scanf() for inputting the interactive information. If you try to use gets(), you may get VERY frustrated.</p> <p>In essence, all numbers appearing in the report should be right-justified and decimal-aligned. All numbers appearing in the summary should appear without leading spaces (other than the one which normally separates the number from the previous word). Hourly wage amounts CAN be less than 10.00, so be very careful with your formatting. The sample output can appear correct, but you can still be docked a half-point if things don't align properly with hourly wages under $10.00." Additional hints:</p> <ul> <li><p>You may assume that the employee name is always two names, a first name and a last name separated by a space. Also assume that there are never any spaces within a first name or within a last name. This allows you to use two scanf() calls instead of one gets() call. gets() would introduce some oddities that make things not work correctly later down the line. </p></li> <li><p>You may also assume that neither name exceeds 10 characters in length. </p></li> <li><p>The input from the Process another employee? question should be a single character. Assume that N or n will stop the loop, but that any other character will continue the loop.</p></li> </ul> </blockquote> <p>Anyone know how to do this? When I use gets(which he says not to do), the loop screws up on the 2nd time around and it asks for the name and salary all in one line. And if I try to use 2 scanf statements, I get a crash or only 1 of the names input.</p> <p>I was thinking the only way to do it is by outputting the names to a text file, then reading them in again. But is there some other way? I'm not allowed to ask for the names individually. A user might type a full name with one space, as it says in the specs.</p> <p>Here is the code I wrote so far. I also need totals for all the gross', overtime hours and regular hours.</p> <pre><code>//stupid program #include &lt;stdio.h&gt; #include &lt;strings.h&gt; #include &lt;math.h&gt; //global variables FILE *reportfile; //output file char department[21]; int count; char name[21]; float hoursworked; float hourlywage; float overtimehoursworked; float overtimehourlywage; float gross; char again; char firstname; char lastname; float tothoursworked; float totovertimehoursworked; float totgross; const float overtimerate = 1.5; const float overtimethreshold = 40; //hours needed to get overtime //function prototypes void GetInfo(void); void Finalreport(void); //main int main(void) { reportfile = fopen("c:\\class\\kpaul-pay.txt","w"); //open output file ////////////////////////////////////////////////// // initialize accumulating variables ///////////////////////////////////////////////// count = 0; tothoursworked = 0; totovertimehoursworked = 0; totgross = 0; GetInfo(); fclose(reportfile); //close output file return 0; } void GetInfo (void) { printf("Mountain Pacific Corporation\n"); printf("Department Salary Program\n\n"); printf("Please enter the name of the department: "); gets(department); fprintf(reportfile, "Mountain Pacific Corporation\n"); fprintf(reportfile, "Department Salary Program\n\n"); fprintf(reportfile, "%s\n\n", department); fprintf(reportfile, "Employee Reg Hrs Overtime Hrs Gross\n"); fprintf(reportfile, "-----------------------------------------------------------------\n"); do { printf("\nEnter employee #1: "); gets(name); printf("Enter the hourly wage of %s", name); scanf("%f", &amp;hourlywage); printf("\nEnter total number of hours: "); scanf("%f", &amp;hoursworked); if (hoursworked&lt;=overtimethreshold) overtimehoursworked = 0; else if (hoursworked &gt; overtimethreshold) overtimehoursworked = hoursworked - overtimethreshold; gross = (hoursworked*hourlywage) + (overtimehoursworked*overtimehourlywage); fprintf(reportfile, "%s%16.2f(%4.2f)%12.2f(%4.2f) $%7.2f", name, hoursworked, hourlywage, overtimehoursworked, hourlywage * overtimerate, gross); tothoursworked = tothoursworked + hoursworked; totovertimehoursworked = totovertimehoursworked +overtimehoursworked; totgross = totgross + gross; printf("\n"); printf("Would you like another conversion? "); scanf ("%s", &amp;again); printf("\n\n"); } while (again!='N' &amp;&amp; again!='n'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload