Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 code works but numbers in the wrong spot

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
keyo187 Posted - Nov 12 2017 : 10:06:13 PM

/**
*Program Name : cis6Fall2017CarterJHw3Ex1.c
*Discussion : Hw3Ex1
*Written By : Jonathan Carter
*Date : 2017 / 10 / 24
*/
#include <stdio.h>
void displayClassInfoJonathanC(void);
void runMenuHw4Version4(void);
int extractDigitCountVersion4(int);
int extractDigitCountVersion2(int);
int extractDigitVersion1(int);
int main() {
	displayClassInfoJonathanC();
	runMenuHw4Version4();


	return 0;
}

void displayClassInfoJonathanC() {
	printf(
		"\nCIS 6 - Introduction to (C) Programming"
		"\nLaney College"
		"\nJonathan Carter"
		"\n"
		"\nAssignment Information --"
		"\n  Assignment Number : Homework 4,"
		"\n                      Coding Assignment -- Exercise #1"
		"\n  Written by:         Jonathan Carter"
		"\n  Submitted Date:     2017/11/09"
		"\n");
}
int extractDigitCountVersion2(int arg) {
	int digitCount;
	int quotient;
	if (arg != 0) {
		digitCount = 0;
		quotient = arg;
		while (quotient != 0){
			digitCount++;

			quotient /= 10;
		}
	} else {
		digitCount = 1;
	}
	return digitCount;
}


int extractDigitCountVersion4(int arg) {
	int digitCount;
	int tmp;
	tmp = arg;
	digitCount=0;
	do {
		digitCount++;

		tmp /= 10;
	} while (tmp != 0);
	return digitCount;
}
int extractDigitVersion1(int arg) {
	do {
		
		printf("\n  %d",
			((arg < 0) ? -arg : arg) % 10);
		arg /= 10;
	} while (arg != 0);
	printf("\n  %d");

}
void runMenuHw4Version4() {
	int option;
	int usrValue;

	do {
		printf(
			"\n*****************************************"
			"\n*            MENU - HW #4               *"
			"\n*(1) Calling displayAllDigitJonathanC() *"
			"\n* 2. Quit                               *"
			"\n*****************************************");
		printf("\nEnter an integer for option + ENTER: ");
		scanf("%d", &option);
		switch (option) {
		case 1:
			printf("\nEnter an intteger: ");
			scanf("%d", &usrValue);

			if (usrValue < 0) {
				printf("\nCalling displayAllDigitJonathanC()--"
					"\nThis is a negative number."
					"\nThere is/are %d digit(s)"
					"\nThe digit(s) would be\n"  
					"\n%d" , extractDigitCountVersion2(usrValue),usrValue);
					
			}
			else if (usrValue > 0) {
				printf("\nCalling displayAllDigitJonathanC()--"
					"\nThis is a postive number."
					"\nThere is/are %d digit(s)"
					"\nThe digit(s) would be"
					"\n%d\n", extractDigitCountVersion2(usrValue))(((extractDigitVersion1)));
				
				
			}

			else {
				printf("\nThe given value is ZERO!\n");
			}
			break;
		case 2:
			printf("\nHave fun!\n");
			break;
		default:
			printf("\nWrong Option!\n");
		}
	} while (option != 2);
	
}

/*OUTPUT*/

/*YOUR_Logic Issues_Code Issues,
none*/



Enter an intteger: 123456

6
5
4
3
2
1
0
Calling displayAllDigitJona
This is a postive number.
There is/are 6 digit(s)
The digit(s) would be
4
^
what the code looks like now

Calling displayAllDigitJona
This is a postive number.
There is/are 6 digit(s)
The digit(s) would be
6
5
4
3
2
1
i need my code to look like this
3   L A T E S T    R E P L I E S    (Newest First)
accord Posted - Nov 13 2017 : 1:37:42 PM
Are you familiar with https://stackoverflow.com/ ? It's a lovely forum where you can ask any programming-related questions. There are a lot of registered users who can help.
feline Posted - Nov 13 2017 : 05:26:54 AM
This is a program logic problem, nothing to do with VA at all, so sadly not something we can help you with.

But as a suggestion, perhaps try looping across the string, rather than doing arithmetic?
keyo187 Posted - Nov 13 2017 : 12:05:43 AM
Enter an intteger: 123456

6
5
4
3
2
1
0
Calling displayAllDigitJona
This is a postive number.
There is/are 6 digit(s)
The digit(s) would be
4
^
what the code looks like now

Calling displayAllDigitJona
This is a postive number.
There is/are 6 digit(s)
The digit(s) would be
6
5
4
3
2
1
i need my code to look like this

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000