Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 code works but numbers in the wrong spot
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keyo187
New Member

2 Posts

Posted - Nov 12 2017 :  10:06:13 PM  Show Profile  Reply with Quote

/**
*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

Edited by - keyo187 on Nov 13 2017 01:25:38 AM

keyo187
New Member

2 Posts

Posted - Nov 13 2017 :  12:05:43 AM  Show Profile  Reply with Quote
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
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18724 Posts

Posted - Nov 13 2017 :  05:26:54 AM  Show Profile  Reply with Quote
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?

zen is the art of being at one with the two'ness
Go to Top of Page

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Nov 13 2017 :  1:37:42 PM  Show Profile  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000