[color=dark red]
Code follows after 8 remarks below.[/color]
1) I removed your drawing. It is buggy. I skipped C and jumped from Pascal to C++, so I am not good with "printf()". But a better approach in general is to make a 2 dimensional array (lets say 40x40 for now) and develop your console drawing on paper in that 40x40 array and print it with a "for" loop in a "for" loop.
2) I removed some annoyances for my self (comments). Sorry about that.
3) Added <ctype.h> for "toupper()".
4) Outcommented "printf("\n\nCost: $%d Peak: %d Off: %d", Cost, Peak, Off);". Added "cout <<..." and <iostream.h> to demonstrate the original buggy line of code. The "cout" version works correctly.
5) Outcommented "N, O, P, Y" to avoid warning: unreferenced local variable.
6) Check "old fashioned" conversion method in the Peak/Off calculation.
7) Input stored in a reference variable instead of value (check for "&" symbols in "Length" and "Ans2". Avoiding run-time errors this way.
8) Hint: Why a double precision? Cents go to two decimals anyway.
Code:
/*
Virtual cell phone written in C to calculate cell phone usage,
Display cost per minute over the fake phones service plan,
Displays the amount of service plan time used in Peak minutes and Off
peak minutes.
As more calls are made, the screen for the virtual phone will refresh
to display
the changes made in minutes and costs.
*/
#include <stdio.h>
#include<ctype.h>
#include <iostream.h>
int main()
{
double Fee;
float Cost;
int Length, Off, Peak;
char Ans1, Ans2; // ,N, O, P, Y,
Cost = 0.00;
Fee = 0.39;
Length = 0;
Off = 0;
Peak = 0;
while(Ans1='Y')
{
printf(" \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
//printf("\n\nCost: $%d Peak: %d Off: %d", Cost, Peak, Off);
cout<<"Cost: $"<<Cost<<" "<<"Peak: "<<Peak<<" "<<"Off: "<<Off<<endl;
printf("\n\nWould you like to make a call?[Y/N] ");
scanf("%s", &Ans1);
if(Ans1 == 'Y' || Ans1 == 'y')
{
printf("\nHow many minutes is the call?");
scanf("%d", &Length);
printf("\nIs that Peak or Off minutes?[P/O]");
scanf("%s", &Ans2);
Ans2 = toupper(Ans2);
if(Ans2 == 'P')
Peak = Peak + Length;
else
Off = Off + Length;
if(Peak > 30)
Cost += (float)((Peak - 30) * Fee);
if(Off > 200)
Cost += (float)((Off - 200) * Fee);
}
}
return 0;
}