Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7976493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:55:24+00:00 2026-06-04T08:55:24+00:00

So here is my first ultra beginner computer programming question in C. I need

  • 0

So here is my first ultra beginner computer programming question in C.

I need to set it up so that someone can type in their full name on the input. Here is part of the specs –

“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.

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.

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:

  • 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.

  • You may also assume that neither name exceeds 10 characters in length.

  • 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.

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.

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.

Here is the code I wrote so far. I also need totals for all the gross’, overtime hours and regular hours.

//stupid program

#include <stdio.h>
#include <strings.h>
#include <math.h>

//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", &hourlywage);

   printf("\nEnter total number of hours: ");
   scanf("%f", &hoursworked);

   if (hoursworked<=overtimethreshold)
    overtimehoursworked = 0;

   else if (hoursworked > 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", &again);

      printf("\n\n");

   } while (again!='N' && again!='n');

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:55:26+00:00Added an answer on June 4, 2026 at 8:55 am

    Careful use of the scanf format string is needed. %s indicates a string that is delimited by a white space, in non technical terms, scanf will read characters until it finds a whitespace character such as a tab or space.

    This poses a problem for reading multiple words, this can be solved by using multiple %s in the format string, you must provide a seperate array for each word as an argument after the format string e.g.

    scanf("%s%s%s", string1, string2, string3)
    

    This scanf call expects three words from the user, where each word is delimited by a white space. Make sure there is allocated memory for each of arrays though otherwise you will write into memory the program does not own normally causing the program to crash. The exact same effect to the code above can be achieved by using scanf multiple times with a single %s in the format string.

    If you need everything as one string the same array you can use strcat which will concatenate two strings together. The function is simple to use, but once again make sure your arguments are allocated arrays before calling strcat otherwise it will likely cause a crash or unexpected behaviour.

    Here are references to both functions:

    scanf – http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

    strcat – http://www.cplusplus.com/reference/clibrary/cstring/strcat/

    Hope this helps =]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First question here: it is a very short yet fundamental thing in Java that
First Question in here :) (AS3) First off, how do I access a variable
This is my first here in Stackoverflow. So I just want to ask question
Don't know if maybe this question belongs on serverfault, but I'll try here first.
n00b here (first Android project). I have been given a custom video codec that
Let me try to set the scenario here first. This is done using ASP.NET
Borderline ServerFault question, but figured I'd try here first since I've had luck with
First here's what I'm using and trying to do: the minimal setup for this
Here is the first part of my controller code: public class ControlMController : Controller
Here is my first attempt at validating XML with XSD. The XML file to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.